Home | History | Annotate | Download | only in conscrypt
      1 /*
      2  * Copyright 2017 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package org.conscrypt;
     18 
     19 import java.io.InputStream;
     20 import java.security.InvalidKeyException;
     21 import java.security.NoSuchAlgorithmException;
     22 import java.security.PublicKey;
     23 import org.conscrypt.OpenSSLX509CertificateFactory.ParsingException;
     24 
     25 /**
     26  * Helper to initialize the JNI libraries. This version runs when compiled
     27  * as part of the platform.
     28  *
     29  * @hide
     30  */
     31 @Internal
     32 public final class InternalUtil {
     33     public static PublicKey logKeyToPublicKey(byte[] logKey)
     34             throws NoSuchAlgorithmException {
     35         try {
     36             return new OpenSSLKey(NativeCrypto.EVP_parse_public_key(logKey)).getPublicKey();
     37         } catch (ParsingException e) {
     38             throw new NoSuchAlgorithmException(e);
     39         }
     40     }
     41 
     42     public static PublicKey readPublicKeyPem(InputStream pem) throws InvalidKeyException, NoSuchAlgorithmException {
     43         return OpenSSLKey.fromPublicKeyPemInputStream(pem).getPublicKey();
     44     }
     45 
     46     public static byte[] getOcspSingleExtension(
     47             byte[] ocspResponse, String oid, OpenSSLX509Certificate x509,
     48             OpenSSLX509Certificate issuerX509) {
     49         return NativeCrypto.get_ocsp_single_extension(ocspResponse, oid, x509.getContext(), x509,
     50                 issuerX509.getContext(), issuerX509);
     51     }
     52 
     53     private InternalUtil() {
     54     }
     55 }
     56