SSLFactory

xiaoxiao2021-03-06  105

/ ** * @Author: bcoffman@paypal.com * a secure socket layer factory. * /

Package com.paypal.Api.client; import java.lang. *; import java.net. *; import javax.net. *; import java.io. *; import java.utility. *; Import java.security. * Import javax.net.ssl. *;

/ ** * Default TrustManager checks that a cert is signed by a well known * certificate authority, like Verisign or Thawte. * / Class RelaxedX509TrustManager implements X509TrustManager {public boolean checkClientTrusted (java.security.cert.X509Certificate [] chain) {return true ;} public boolean isServerTrusted (java.security.cert.X509Certificate [] chain) {return true;} public java.security.cert.X509Certificate [] getAcceptedIssuers () {return null;} public void checkClientTrusted (java.security.cert. X509certificate [] chain, string authtype) {} public void checkservertrusted (java.security.cert.x509certificate [] chain, string authtype) {}}}

/ ** * The SSL Factory Pattern (AS in Design Patterns) That Produces An SSL CHANNEL. * WE Specify A CERT, AND THE Passwor, AS Well As The Format of the Cert. The * Supported Types Are PCKS12, And Jks. You Must specify * / public class sslfactory extension org.apache.axis.components.net.jsseSocketFactory {public sslfactory (HashTable Attributes) {Super (attributes);}

Protected void initFactory () throws ioException {sslfactory = get_sslfactory ();

protected SSLSocketFactory get_SSLFactory () throws IOException {String cert_password = ""; String cert_format = ""; String cert_file = ""; try {SimpleConfigFile cfg = new SimpleConfigFile ();. // Uses previously instantiated file cert_file = cfg.val ( " CERT_FILE "); cert_password = cfg.val (" CERT_PASSWORD "); CERT_FORMAT = cfg.val (" CERT_FORMAT "); if (CERT_FORMAT == NULL) {CERT_FORMAT =" PKCS12 "; // default value.} if (CERT_FAULT VALUE) = null || cert_password == null) {throw new IOException ( "missing cert info");}} catch (Exception e) {System.err.println ( "com.paypal.api.client.SSLFactory: Problems with keystore configuration "); throw new IOException (" Problems with keystore configuration ");} char [] keypass = cert_password.toCharArray (); char [] storepass = cert_password.toCharArray (); try {// InputFileStream ifs = getClass () getResourceAsStream. (CERT_FILE); File File = New File (CERT_FILE); IF (! file.canread ()) {system.err.println ("com.paypal.api.client.sslfactory: can't Find / Read Cert File: /" " CERT_FILE " / "."); throw new IOException ( "com.paypal.api.client.SSLFactory: Can not find / read cert file: /". " cert_file " / "");} FileInputStream fin = new FileInputStream (file); SecureRandom random = SecureRandom.getInstance ("Sha1prng"); Random.SetSeed (system.currenttimemillis ()); keystore ks = null; if (CERT_FORMAT.TOUPPERCASE () == "JKS"

转载请注明原文地址:https://www.9cbs.com/read-124722.html

New Post(0)