Rebind content key with specified content key and X509 Certificate.

@param contentKeyId
the content key id
@param x509Certificate
the x509 certificate
@return the entity action operation
183260
public static EntityTypeActionOperation<String> rebind(String contentKeyId,
            String x509Certificate) {
        return new RebindContentKeyActionOperation(contentKeyId,
                x509Certificate);
    }
18925
public final X509Certificate retrieveCertificate(KeyStore keyStore, String certificateName) {
        try {
            logger.entry();
            X509Certificate certificate = (X509Certificate) keyStore.getCertificate(certificateName);
            logger.exit();
            return certificate;
        } catch (KeyStoreException e) {
            RuntimeException exception = new RuntimeException("An unexpected exception occurred while attempting to retrieve a certificate.", e);
            logger.error(exception.toString());
            throw exception;
        }
    }
1355178
public static java.security.cert.X509Certificate convert(javax.security.cert.X509Certificate cert) {
        try {
            byte[] encoded = cert.getEncoded();
            ByteArrayInputStream bis = new ByteArrayInputStream(encoded);
            java.security.cert.CertificateFactory cf
                = java.security.cert.CertificateFactory.getInstance("X.509");
            return (java.security.cert.X509Certificate)cf.generateCertificate(bis);
        } catch (java.security.cert.CertificateEncodingException e) {
        } catch (javax.security.cert.CertificateEncodingException e) {
        } catch (java.security.cert.CertificateException e) {
        }
        return null;
    }
114957
public static X509CertImpl toImpl(X509Certificate cert)
            throws CertificateException {
        if (cert instanceof X509CertImpl) {
            return (X509CertImpl)cert;
        } else {
            return X509Factory.intern(cert);
        }
    }
115580
public X509Certificate retrieveSignerCertificate() throws Exception {

        // TO-DO: The real way is we get the keyStore value from
        // the audit Policy, get the audit truststore, retrieve
        // the public certificate and extract the public key from
        // the public certificate.   But since we don't have the WCCM
        // model change, we'll have to hardcode where the truststore is

        PublicKey publicKey = null;

        if (tc.isDebugEnabled()) {
            Tr.debug(tc, "signerAlias: " + signerAlias + " signerType: " + signerType + " signerProvider: " + signerProvider +
                         " signerKeyFileLocation: " + signerKeyFileLocation);
        }

        KeyStore ks = null;
        try {
            ks = KeyStore.getInstance("JKS");
            InputStream is = openKeyStore(signerKeyFileLocation);
            X509Certificate cert = (X509Certificate) ks.getCertificate(signerAlias);

            return cert;
        } catch (java.net.MalformedURLException me) {
            if (tc.isDebugEnabled())
                Tr.debug(tc, "Exception opening keystore: malformed URL", me.getMessage());
            throw new Exception(me.getMessage());
        } catch (java.security.KeyStoreException ke) {
            if (tc.isDebugEnabled())
                Tr.debug(tc, "Exception opening keystore.", ke.getMessage());
            throw new Exception(ke.getMessage());
        } catch (java.io.IOException ioe) {
            if (tc.isDebugEnabled())
                Tr.debug(tc, "Exception opening keystore.", ioe.getMessage());
            throw new Exception(ioe.getMessage());

        }
    }
210961
public static void validateContentId(String contentID)
        throws InvalidIdException {
        if (contentID == null) {
            String err = "Content ID must be at least 1 character long";
            throw new InvalidIdException(err);
        }

        if (contentID.contains("?")) {
            String err = "Content ID may not include the '?' character";
            throw new InvalidIdException(err);
        }

        if (contentID.contains("\\")) {
            String err = "Content ID may not include the '\\' character";
            throw new InvalidIdException(err);
        }

        int utfLength;
        int urlLength;
        try {
            utfLength = contentID.getBytes("UTF-8").length;
            String urlEncoded = URLEncoder.encode(contentID, "UTF-8");
            urlLength = urlEncoded.getBytes("UTF-8").length;
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }

        if (utfLength > 1024 || urlLength > 1024) {
            String err =
                "Content ID must <= 1024 bytes after URL and UTF-8 encoding";
            throw new InvalidIdException(err);
        }
    }
1310163
X509Certificate selectCertificate(final CertStore store,
			final Collection<X509CertSelector> selectors) throws CertStoreException {
		for (CertSelector selector : selectors) {
			LOGGER.debug("Selecting certificate using {}", selector);
			Collection<? extends Certificate> certs = store
					.getCertificates(selector);
			if (certs.size() > 0) {
				LOGGER.debug("Selected {} certificate(s) using {}",
						certs.size(), selector);
				return (X509Certificate) certs.iterator().next();
			} else {
				LOGGER.debug("No certificates selected");
			}
		}
		return (X509Certificate) store.getCertificates(null).iterator().next();
	}
1145140
private X509Certificate loadX509FromPEMFile(String filename) {
        try {
            return (X509Certificate) CertificateFactory.getInstance("X.509").generateCertificate(FileReader.openStreamToFileFromClassPathOrPath(filename));
        } catch (Exception e) {
            throw new RuntimeException("Exception reading X509 from PEM file", e);
        }
    }
262249
public static javax.security.cert.X509Certificate convert(java.security.cert.X509Certificate cert) {
        try {
            byte[] encoded = cert.getEncoded();
            return javax.security.cert.X509Certificate.getInstance(encoded);
        } catch (java.security.cert.CertificateEncodingException e) {
        } catch (javax.security.cert.CertificateEncodingException e) {
        } catch (javax.security.cert.CertificateException e) {
        }
        return null;
    }
267726
public static String link(Key k, String content) {
    return link(k, content, null, null, null);
  }
475231
public static X509Certificate getCertificate(String alias, File storeFile, String storePassword) {
        try {
            KeyStore store = openKeyStore(storeFile, storePassword);
            X509Certificate caCert = (X509Certificate) store.getCertificate(alias);
            return caCert;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
1322666
static X509Certificate selfSignedCertificate() throws CertificateException {
        return (X509Certificate) SslContext.X509_CERT_FACTORY.generateCertificate(
                new ByteArrayInputStream(CERT.getBytes(CharsetUtil.US_ASCII))
        );
    }
1080656
@Override
    public void updateState(X509Certificate cert)
        throws CertificateException, IOException, CertPathValidatorException {

        if (cert == null)
            return;

        X509CertImpl icert = X509CertImpl.toImpl(cert);

        /* see if certificate key has null parameters */
        if (PKIX.isDSAPublicKeyWithoutParams(icert.getPublicKey())) {
            keyParamsNeededFlag = true;
        }

        /* update certificate */
        this.cert = icert;

        /* update issuer DN */
        issuerDN = cert.getIssuerX500Principal();

        if (!X509CertImpl.isSelfIssued(cert)) {

            /*
             * update traversedCACerts only if this is a non-self-issued
             * intermediate CA cert
             */
            if (!init && cert.getBasicConstraints() != -1) {
                traversedCACerts++;
            }
        }

        /* update subjectNamesTraversed only if this is the EE cert or if
           this cert is not self-issued */
        if (init || !X509CertImpl.isSelfIssued(cert)){
            X500Principal subjName = cert.getSubjectX500Principal();
            subjectNamesTraversed.add(X500Name.asX500Name(subjName));

            try {
                SubjectAlternativeNameExtension subjAltNameExt
                    = icert.getSubjectAlternativeNameExtension();
                if (subjAltNameExt != null) {
                    GeneralNames gNames = subjAltNameExt.get(
                            SubjectAlternativeNameExtension.SUBJECT_NAME);
                    for (GeneralName gName : gNames.names()) {
                        subjectNamesTraversed.add(gName.getName());
                    }
                }
            } catch (IOException e) {
                if (debug != null) {
                    debug.println("ForwardState.updateState() unexpected "
                        + "exception");
                    e.printStackTrace();
                }
                throw new CertPathValidatorException(e);
            }
        }

        init = false;
    }
275497
public static EntityTypeActionOperation<String> getProtectionKeyId(
            ContentKeyType contentKeyType) {
        return new GetProtectionKeyIdActionOperation("GetProtectionKeyId")
                .addQueryParameter("contentKeyType",
                        String.format("%d", contentKeyType.getCode()))
                .setAcceptType(MediaType.APPLICATION_XML_TYPE);
    }
831841
public static List<String> getExtendedKeyUsage(X509Certificate cert)
        throws CertificateParsingException {
        try {
            byte[] ext = cert.getExtensionValue(EXTENDED_KEY_USAGE_OID);
            if (ext == null)
                return null;
            DerValue val = new DerValue(ext);
            byte[] data = val.getOctetString();

            ExtendedKeyUsageExtension ekuExt =
                new ExtendedKeyUsageExtension(Boolean.FALSE, data);
            return Collections.unmodifiableList(ekuExt.getExtendedKeyUsage());
        } catch (IOException ioe) {
            throw new CertificateParsingException(ioe);
        }
    }
676320
public function getContentKeyAuthorizationPolicyOption($contentKeyAuthorizationOptions)
    {
        $contentKeyAuthorizationOptionsId = Utilities::getEntityId(
            $contentKeyAuthorizationOptions,
            'WindowsAzure\MediaServices\Models\ContentKeyAuthorizationPolicyOption'
        );

        return ContentKeyAuthorizationPolicyOption::createFromOptions(
            $this->_getEntity("ContentKeyAuthorizationPolicyOptions('{$contentKeyAuthorizationOptionsId}')")
        );
    }
349668
public static RevocationStatus check(X509Certificate cert,
                                         X509Certificate issuerCert,
                                         URI responderURI,
                                         X509Certificate responderCert,
                                         Date date, List<Extension> extensions)
        throws IOException, CertPathValidatorException
    {
        CertId certId = null;
        try {
            X509CertImpl certImpl = X509CertImpl.toImpl(cert);
            certId = new CertId(issuerCert, certImpl.getSerialNumberObject());
        } catch (CertificateException | IOException e) {
            throw new CertPathValidatorException
                ("Exception while encoding OCSPRequest", e);
        }
        OCSPResponse ocspResponse = check(Collections.singletonList(certId),
            responderURI, issuerCert, responderCert, date, extensions);
        return (RevocationStatus) ocspResponse.getSingleResponse(certId);
    }