public void TestStoreAndRetrieve() { DigitalSignatureServiceClient client = new DigitalSignatureServiceClientImpl(DSS_LOCATION); // store StorageInfoDO storageInfo = client.Store(unsignedDocument, "text/xml"); Assert.NotNull(storageInfo); Assert.NotNull(storageInfo.Artifact); Assert.NotNull(storageInfo.NotBefore); Assert.NotNull(storageInfo.NotAfter); // verify store Console.WriteLine("Artifact: " + storageInfo.Artifact); Console.WriteLine("NotBefore: " + storageInfo.NotBefore); Console.WriteLine("NotAfter: " + storageInfo.NotAfter); // retrieve byte[] resultDocument = client.Retrieve(storageInfo.Artifact); // verify retrieve Assert.NotNull(resultDocument); Assert.True(Arrays.AreEqual(unsignedDocument, resultDocument)); }
private void SetSignatureRequest(bool signed, bool artifact, String languageValue) { if (FileUpload1.HasFile) { try { // read to be signed document byte[] doc = new byte[FileUpload1.PostedFile.ContentLength]; FileUpload1.PostedFile.InputStream.Read(doc, 0, FileUpload1.PostedFile.ContentLength); // construct post parameter values String signatureRequestValue = null; String signatureRequestIdValue = null; String contentTypeValue = FileUpload1.PostedFile.ContentType; String relayStateValue = Guid.NewGuid().ToString(); String targetValue = Request.Url.ToString(); if (artifact) { // upload using WS StorageInfoDO storageInfo = getClient().Store(doc, FileUpload1.PostedFile.ContentType); signatureRequestIdValue = storageInfo.Artifact; } else { signatureRequestValue = Convert.ToBase64String(doc); } // construct service signature if requested ServiceSignatureDO serviceSignature = null; if (signed) { RSACryptoServiceProvider rsa = KeyStoreUtil.GetPrivateKeyFromPfx(TEST_PFX_PATH, TEST_PFX_PASSWORD, true); X509Certificate2 certificate = KeyStoreUtil.GetCertificateFromPfx(TEST_PFX_PATH, TEST_PFX_PASSWORD, true); List <X509Certificate2> certificateChain = new List <X509Certificate2>(); certificateChain.Add(certificate); serviceSignature = SignatureRequestUtil.CreateServiceSignature(rsa, certificateChain, signatureRequestValue, signatureRequestIdValue, targetValue, languageValue, contentTypeValue, relayStateValue); } // set signature request post parameters if (null != signatureRequestValue) { SignatureRequest.Value = signatureRequestValue; SignatureRequestId.Visible = false; } else { SignatureRequest.Visible = false; SignatureRequestId.Value = signatureRequestIdValue; } if (null != serviceSignature) { ServiceSigned.Value = serviceSignature.ServiceSigned; ServiceSignature.Value = serviceSignature.ServiceSignature; ServiceCertificateChainSize.Value = serviceSignature.ServiceCertificateChainSize; ServiceCertificate.Value = serviceSignature.ServiceCertificates[0]; ServiceCertificate.ID = "ServiceCertificate.1"; } else { ServiceSigned.Visible = false; ServiceSignature.Visible = false; ServiceCertificateChainSize.Visible = false; ServiceCertificate.Visible = false; } ContentType.Value = contentTypeValue; RelayState.Value = relayStateValue; target.Value = targetValue; language.Value = languageValue; // store signature request state on session for response validation Session[SIGNATURE_REQUEST_SESSION_PARAM] = signatureRequestValue; Session[SIGNATURE_REQUEST_ID_SESSION_PARAM] = signatureRequestIdValue; Session[RELAY_STATE_SESSION_PARAM] = relayStateValue; Session[TARGET_SESSION_PARAM] = targetValue; Session[CONTENT_TYPE_SESSION_PARAM] = contentTypeValue; // ready for sign request SignForm.Action = dssLocation; Button1.Text = "Sign Document"; hideRequest(); // display some info Label1.Text = "File name: " + FileUpload1.PostedFile.FileName + "<br>" + FileUpload1.PostedFile.ContentLength + " kb<br>" + "Content type: " + FileUpload1.PostedFile.ContentType + "<br>"; if (null != signatureRequestIdValue) { Label1.Text += "Document ID: " + signatureRequestIdValue + "<br>"; } if (null != serviceSignature) { Label1.Text += "Service Signed: " + serviceSignature.ServiceSigned + "<br>"; } } catch (Exception ex) { Label1.Text = "ERROR: " + ex.Message.ToString(); } } else { Label1.Text = "You have not specified a file."; } }