Exemple #1
0
        public async Task <CreateSigningRequestApiModel> StartSigningAsync(string id, string csr)
        {
            try
            {
                var groups = await this._opcVaultServiceClient.GetCertificateGroupsConfigurationAsync();

                string defaultGroupId = null, defaultTypeId = null;
                if (groups.Groups.Count > 0)
                {
                    defaultGroupId = groups.Groups[0].Name;
                    defaultTypeId  = groups.Groups[0].CertificateType;
                }

                var application = await this._opcVaultServiceClient.GetApplicationAsync(id);

                var request = new CreateSigningRequestApiModel()
                {
                    ApplicationId      = id,
                    CertificateGroupId = defaultGroupId,
                    CertificateTypeId  = defaultTypeId,
                    CertificateRequest = csr
                };
                return(request);
            }
            catch (Exception ee)
            {
                await Xamarin.Forms.Application.Current.MainPage.DisplayAlert("An error has occurred", "Exception message: " + ee.Message, "Dismiss");

                return(null);
            }
        }
Exemple #2
0
        public async Task <string> CreateSigningRequestAsync([FromBody] CreateSigningRequestApiModel signingRequest)
        {
            if (signingRequest == null)
            {
                throw new ArgumentNullException(nameof(signingRequest));
            }
            string authorityId = User.Identity.Name;

            return(await this._certificateRequest.StartSigningRequestAsync(
                       signingRequest.ApplicationId,
                       signingRequest.CertificateGroupId,
                       signingRequest.CertificateTypeId,
                       signingRequest.ToServiceModel(),
                       authorityId));
        }
        public NodeId StartSigningRequest(
            NodeId applicationId,
            string certificateGroupId,
            string certificateTypeId,
            byte[] certificateRequest,
            string authorityId)
        {
            string appId = OpcVaultClientHelper.GetServiceIdFromNodeId(applicationId, NamespaceIndex);

            if (string.IsNullOrEmpty(appId))
            {
                throw new ServiceResultException(StatusCodes.BadNotFound, "The ApplicationId is invalid.");
            }

            if (String.IsNullOrWhiteSpace(certificateTypeId))
            {
                throw new ServiceResultException(StatusCodes.BadInvalidArgument, "The CertificateTypeId does not refer to a supported CertificateType.");
            }

            if (String.IsNullOrWhiteSpace(certificateGroupId))
            {
                throw new ServiceResultException(StatusCodes.BadInvalidArgument, "The CertificateGroupId does not refer to a supported CertificateGroup.");
            }

            try
            {
                var model = new CreateSigningRequestApiModel(
                    appId,
                    certificateGroupId,
                    certificateTypeId,
                    Convert.ToBase64String(certificateRequest)
                    );

                string requestId = _opcVaultServiceClient.CreateSigningRequest(model);
                return(OpcVaultClientHelper.GetNodeIdFromServiceId(requestId, NamespaceIndex));
            }
            catch (HttpOperationException httpEx)
            {
                // TODO: return matching ServiceResultException
                //throw new ServiceResultException(StatusCodes.BadNotFound);
                //throw new ServiceResultException(StatusCodes.BadInvalidArgument);
                //throw new ServiceResultException(StatusCodes.BadUserAccessDenied);
                //throw new ServiceResultException(StatusCodes.BadRequestNotAllowed);
                //throw new ServiceResultException(StatusCodes.BadCertificateUriInvalid);
                throw new ServiceResultException(httpEx, StatusCodes.BadNotSupported);
            }
        }
        public async Task <string> StartSigningAsync(
            CreateSigningRequestApiModel request)
        {
            if (request.CertificateRequest != null)
            {
                string id;
                try
                {
                    id = await this._opcVaultServiceClient.CreateSigningRequestAsync(request);

                    return(id);
                }
                catch (Exception ee)
                {
                    await Xamarin.Forms.Application.Current.MainPage.DisplayAlert("Failed to create Signing Request.", "Exception message: " + ee.Message, "Dismiss");
                }
                return(null);
            }
            return(null);
        }
Exemple #5
0
 /// <summary>
 /// Initializes a new instance of the StartSigningRequestUploadModel
 /// class.
 /// </summary>
 public CreateSigningRequestUploadApiModel(CreateSigningRequestApiModel apiModel)
 {
     ApiModel = apiModel;
     CustomInit();
 }