void resetDS() { ds = new DigSigUtil(); ds.put(DigSigUtil.SIGNATURE_KEYSTORE_FILE, path + Path.DirectorySeparatorChar + "cert.pfx"); ds.put(DigSigUtil.SIGNATURE_KEYSTORE_FILETYPE, "PFX"); ds.put(DigSigUtil.SIGNATURE_KEYSTORE_FILE_PASSWORD, "password"); ds.put(DigSigUtil.SIGNATURE_KEYSTORE_KEY_ALIAS, "selfsigned"); //the friendly name = alias //ds.put(DigSigUtil.TRUSTSTORE_FILE, "./src/test/resources/truststore.jks"); //ds.put(DigSigUtil.TRUSTSTORE_FILETYPE, "JKS"); //ds.put(DigSigUtil.TRUSTSTORE_FILE_PASSWORD, "Test"); ds.put(DigSigUtil.SIGNATURE_OPTION_CERT_INCLUSION_BASE64, "true"); ds.put(DigSigUtil.SIGNATURE_OPTION_CERT_INCLUSION_SUBJECTDN, "true"); ds.put(DigSigUtil.SIGNATURE_OPTION_CERT_INCLUSION_SERIAL, "true"); ds.put(DigSigUtil.CHECK_TIMESTAMPS, "true"); }
public DigitalSignatureTests() { if (Environment.GetEnvironmentVariable("debug") != null && Environment.GetEnvironmentVariable("debug").Equals("true", StringComparison.CurrentCultureIgnoreCase)) { serialize = true; } Console.Out.WriteLine(Directory.GetCurrentDirectory()); path = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "resources"; if (!Directory.Exists(path)) { path = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + ".." + Path.DirectorySeparatorChar + ".." + Path.DirectorySeparatorChar + "resources"; Console.Out.WriteLine(path); } if (!Directory.Exists(path)) { path = Environment.GetEnvironmentVariable("JUDDI_TEST_RES"); Console.Out.WriteLine(path); } if (path == null || !Directory.Exists(path)) { path = null; Console.Out.WriteLine("uh oh, I can't find the resources directory, override with the environment variable JUDDI_TEST_RES=<path>"); } ds = new DigSigUtil(); ds.put(DigSigUtil.SIGNATURE_KEYSTORE_FILE, path + Path.DirectorySeparatorChar + "cert.pfx"); ds.put(DigSigUtil.SIGNATURE_KEYSTORE_FILETYPE, "PFX"); ds.put(DigSigUtil.SIGNATURE_KEYSTORE_FILE_PASSWORD, "password"); ds.put(DigSigUtil.SIGNATURE_KEYSTORE_KEY_ALIAS, "selfsigned"); //the friendly name = alias //ds.put(DigSigUtil.TRUSTSTORE_FILE, "./src/test/resources/truststore.jks"); //ds.put(DigSigUtil.TRUSTSTORE_FILETYPE, "JKS"); //ds.put(DigSigUtil.TRUSTSTORE_FILE_PASSWORD, "Test"); ds.put(DigSigUtil.SIGNATURE_OPTION_CERT_INCLUSION_BASE64, "true"); ds.put(DigSigUtil.SIGNATURE_OPTION_CERT_INCLUSION_SUBJECTDN, "true"); ds.put(DigSigUtil.SIGNATURE_OPTION_CERT_INCLUSION_SERIAL, "true"); ds.put(DigSigUtil.CHECK_TIMESTAMPS, "true"); }
/** * Registers a UDDI binding template that represents the subscription * callback endpoint * * @param client * @param cfg_node_name * @param bt - Binding Template * @param behavior * @return * @throws ServiceAlreadyStartedException * @throws SecurityException * @throws ConfigurationException * @throws TransportException * @throws DispositionReportFaultMessage * @throws RemoteException * @throws UnexpectedException * @throws RegistrationAbortedException * @throws UnableToSignException */ public static bindingTemplate registerBinding(UDDIClient client, String cfg_node_name, bindingTemplate bt, SignatureBehavior behavior) { log.info("Attempting to register binding " + bt.bindingKey); UDDIClerk clerk = client.getClerk(cfg_node_name); Transport tp = client.getTransport(cfg_node_name); UDDI_Inquiry_SoapBinding uddiInquiryService = tp.getUDDIInquiryService(); UDDI_Publication_SoapBinding uddiPublishService = tp.getUDDIPublishService(); String token = clerk.getAuthToken(clerk.getUDDINode().getSecurityUrl()); switch (behavior) { case SignatureBehavior.AbortIfSigned: if (CheckExistingBindingForSignature(bt.bindingKey, uddiInquiryService, token, behavior)) { throw new RegistrationAbortedException("Aborting, Either the item exists and is signed"); } if (CheckServiceAndParentForSignature(bt.serviceKey, uddiInquiryService, token)) { throw new RegistrationAbortedException("Aborting, Either the service or busness is signed"); } break; case SignatureBehavior.DoNothing: break; case SignatureBehavior.SignAlways: try { DigSigUtil ds = new DigSigUtil(client.getClientConfig().getDigitalSignatureConfiguration()); bt = (bindingTemplate)ds.signUddiEntity(bt); } catch (Exception ex) { log.error("Unable to sign", ex); throw new UnableToSignException("Unable to sign", ex); } break; case SignatureBehavior.SignOnlyIfParentIsntSigned: if (!CheckServiceAndParentForSignature(bt.serviceKey, uddiInquiryService, token)) { try { DigSigUtil ds = new DigSigUtil(client.getClientConfig().getDigitalSignatureConfiguration()); bt = (bindingTemplate)ds.signUddiEntity(bt); } catch (Exception ex) { log.error("Unable to sign", ex); throw new UnableToSignException("Unable to sign", ex); } } break; } save_binding sb = new save_binding(); sb.authInfo = (token); sb.bindingTemplate = new bindingTemplate[] { bt }; bindingDetail saveBinding = uddiPublishService.save_binding(sb); log.info("Binding registered successfully"); if (saveBinding.bindingTemplate == null || saveBinding.bindingTemplate.Length > 1) { throw new UnexpectedResponseException("The number of binding templates returned was unexpected, count=" + (saveBinding.bindingTemplate == null ? "none" : saveBinding.bindingTemplate.Length.ToString())); } return(saveBinding.bindingTemplate[0]); }
/// <summary> /// From file /// create business, save in juddi, download from juddi, sign and save it, /// download it again, verify sig is valid /// </summary> /// <param name="config"></param> void SignSaveAndVerifyToJuddi(String config) { UDDIClient clerkManager = null; Transport transport = null; UDDIClerk clerk = null; try { clerkManager = new UDDIClient(config); transport = clerkManager.getTransport("default"); UDDI_Security_SoapBinding security = transport.getUDDISecurityService(); UDDI_Inquiry_SoapBinding inquiry = transport.getUDDIInquiryService(); UDDI_Publication_SoapBinding publish = transport.getUDDIPublishService(); clerk = clerkManager.getClerk("default"); businessEntity be = new businessEntity(); be.name = new name[] { new name("Test biz", "en") }; Console.Out.WriteLine("saving test biz"); businessEntity complete = clerk.register(be); Console.Out.WriteLine("attempting to sign"); DigSigUtil ds = new DigSigUtil(clerkManager.getClientConfig().getDigitalSignatureConfiguration()); businessEntity signed = (businessEntity)ds.signUddiEntity(complete); PrintUDDI <businessEntity> p = new PrintUDDI <businessEntity>(); Console.Out.WriteLine("signed successfully!"); if (serialize) { Console.Out.WriteLine(p.print(signed)); } Console.Out.WriteLine("attempting verify signature locally"); String err = ""; bool valid = ds.verifySignedUddiEntity(signed, out err); Console.Out.WriteLine("Signature is " + (valid ? "Valid, Yippy!" : "Invalid!") + " msg: " + err); Assert.True(valid); Assert.True(String.IsNullOrEmpty(err)); Console.Out.WriteLine("saving to signed entity to the registry"); clerk.register(signed); Console.Out.WriteLine("reloading content from the server..."); get_businessDetail gsd = new get_businessDetail(); gsd.authInfo = clerk.getAuthToken(clerk.getUDDINode().getSecurityUrl()); gsd.businessKey = new string[] { signed.businessKey }; businessDetail saved = inquiry.get_businessDetail(gsd); Console.Out.WriteLine("done. attempting verify signed entity"); if (serialize) { Console.Out.WriteLine(p.print(saved.businessEntity[0])); } err = ""; valid = ds.verifySignedUddiEntity(saved.businessEntity[0], out err); Console.Out.WriteLine("Signature is " + (valid ? "Valid, Yippy!" : "Invalid!") + " msg: " + err); } catch (Exception ex) { while (ex != null) { System.Console.WriteLine("Error! " + ex.Message); ex = ex.InnerException; } throw ex; } finally { if (transport != null && transport is IDisposable) { ((IDisposable)transport).Dispose(); } if (clerk != null) { clerk.Dispose(); } } }
public static void Run(string[] args) { UDDIClient clerkManager = null; Transport transport = null; UDDIClerk clerk = null; try { clerkManager = new UDDIClient("uddi.xml"); transport = clerkManager.getTransport("default"); UDDI_Security_SoapBinding security = transport.getUDDISecurityService(); UDDI_Inquiry_SoapBinding inquiry = transport.getUDDIInquiryService(); UDDI_Publication_SoapBinding publish = transport.getUDDIPublishService(); clerk = clerkManager.getClerk("default"); find_business fb = new find_business(); fb.authInfo = clerk.getAuthToken(security.Url); fb.findQualifiers = new string[] { UDDIConstants.APPROXIMATE_MATCH }; fb.name = new name[1]; fb.name[0] = new name(UDDIConstants.WILDCARD, "en"); businessList bl = inquiry.find_business(fb); if (bl.businessInfos.Length > 0) { Console.Out.WriteLine(bl.businessInfos[0].name[0].Value); Console.Out.WriteLine("attempting to sign"); businessService sd = clerk.getServiceDetail(bl.businessInfos[0].serviceInfos[0].serviceKey); //pist, the signing config comes from the stuff in in uddi.xml DigSigUtil ds = new DigSigUtil(clerkManager.getClientConfig().getDigitalSignatureConfiguration()); businessService signedsvc = (businessService)ds.signUddiEntity(sd); PrintUDDI <businessService> p = new PrintUDDI <businessService>(); Console.Out.WriteLine("signed successfully!"); Console.Out.WriteLine(p.print(signedsvc)); Console.Out.WriteLine("attempting verify and validate"); String err = ""; bool valid = ds.verifySignedUddiEntity(signedsvc, out err); Console.Out.WriteLine("Signature is " + (valid ? "Valid, Yippy!" : "Invalid!") + " msg: " + err); Console.Out.WriteLine("saving"); clerk.register(signedsvc); Console.Out.WriteLine("reloading content from the server..."); get_serviceDetail gsd = new get_serviceDetail(); gsd.authInfo = clerk.getAuthToken(clerk.getUDDINode().getSecurityUrl()); gsd.serviceKey = new string[] { signedsvc.serviceKey }; sd = inquiry.get_serviceDetail(gsd).businessService[0]; Console.Out.WriteLine(p.print(sd)); Console.Out.WriteLine("attempting verify and validate"); err = ""; valid = ds.verifySignedUddiEntity(sd, out err); Console.Out.WriteLine("Signature is " + (valid ? "Valid, Yippy!" : "Invalid!") + " msg: " + err); } else { Console.Out.WriteLine("no businesses were returned!"); } } catch (Exception ex) { while (ex != null) { System.Console.WriteLine("Error! " + ex.Message); ex = ex.InnerException; } } finally { if (transport != null && transport is IDisposable) { ((IDisposable)transport).Dispose(); } if (clerk != null) { clerk.Dispose(); } } }