def dateToStr(obj): """ Encodes a java.util.Date or java.util.Calendar object to an ISO8601 formatted datetime string. """ cal = None if isinstance(obj, util.Calendar): cal = obj elif isinstance(obj, util.Date): cal = util.Calendar.getInstance() cal.setTime(obj) else: raise Exception('Unable to turn %s into date' % obj) return DatatypeConverter.printDateTime(cal)
from javax.xml.bind import DatatypeConverter print 'Install certificate %s to target %s' % (deployed.name, deployed.container.name) # Load the keystore print 'Loading keystore %s' % (deployed.container.keystore) ks = KeyStore.getInstance(deployed.container.keystoreType) ksfi = FileInputStream(deployed.container.keystore) try: ks.load(ksfi, deployed.container.passphrase) # Load certificates (base64 encoded DER/PEM-encoded certificates) # http://docs.oracle.com/javase/7/docs/api/java/security/cert/CertificateFactory.html#generateCertificates(java.io.InputStream) print 'Loading the certificate(chain)' inStream = ByteArrayInputStream(DatatypeConverter.parseBase64Binary(String(deployed.certificate))) cf = CertificateFactory.getInstance("X.509") chain = cf.generateCertificates(inStream).toArray(jarray.zeros(0, java.security.cert.Certificate)) # Save the private key entry (base64 PKCS8 DER encoded) print 'Storing key/certificate %s (alias=%s) in keystore %s' % (deployed.name, deployed.alias, deployed.container.keystore) kf = KeyFactory.getInstance(deployed.keyAlgorithm) key = kf.generatePrivate(PKCS8EncodedKeySpec(DatatypeConverter.parseBase64Binary(String(deployed.key)))) ks.setEntry(deployed.alias, KeyStore.PrivateKeyEntry(key, chain), KeyStore.PasswordProtection(deployed.keyPassword)) ksfo = FileOutputStream(deployed.container.keystore) try: ks.store(ksfo, deployed.container.passphrase) print 'Stored key/certificate %s (alias=%s) in keystore %s' % (deployed.name, deployed.alias, deployed.container.keystore) finally: ksfo.close()
from javax.xml.bind import DatatypeConverter print 'Install certificate %s to target %s' % (deployed.name, deployed.container.name) if deployed.certificate: # Load the keystore print 'Loading keystore %s' % (deployed.container.keystore) ks = KeyStore.getInstance(deployed.container.keystoreType) ksfi = FileInputStream(deployed.container.keystore) try: ks.load(ksfi, deployed.container.passphrase) # Load certificate(base64 encoded DER/PEM-encoded certificate) print 'Loading the certificate' inStream = ByteArrayInputStream(DatatypeConverter.parseBase64Binary(String(deployed.certificate))) cf = CertificateFactory.getInstance("X.509") cert = cf.generateCertificate(inStream) # Save the certificate print 'Storing certificate %s (alias=%s) in keystore %s' % (deployed.name, deployed.alias, deployed.container.keystore) ks.setCertificateEntry(deployed.alias, cert) ksfo = FileOutputStream(deployed.container.keystore) try: ks.store(ksfo, deployed.container.passphrase) print 'Stored certificate %s (alias=%s) in keystore %s' % (deployed.name, deployed.alias, deployed.container.keystore) finally: ksfo.close() finally: ksfi.close()
def strToDate(s): """ Parses a ISO8601 formatted datetime string into a java.util.Calendar object. """ return DatatypeConverter.parseDateTime(s)