Michael Iedema | 0213786 | 2018-10-09 15:30:01 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | package org.webrtc; |
| 12 | |
| 13 | /** |
| 14 | * Easily storable/serializable version of a native C++ RTCCertificatePEM. |
| 15 | */ |
| 16 | public class RtcCertificatePem { |
| 17 | /** PEM string representation of the private key. */ |
| 18 | public final String privateKey; |
| 19 | /** PEM string representation of the certificate. */ |
| 20 | public final String certificate; |
| 21 | /** Default expiration time of 30 days. */ |
| 22 | private static final long DEFAULT_EXPIRY = 60 * 60 * 24 * 30; |
| 23 | |
| 24 | /** Instantiate an RtcCertificatePem object from stored strings. */ |
| 25 | @CalledByNative |
| 26 | public RtcCertificatePem(String privateKey, String certificate) { |
| 27 | this.privateKey = privateKey; |
| 28 | this.certificate = certificate; |
| 29 | } |
| 30 | |
| 31 | @CalledByNative |
| 32 | String getPrivateKey() { |
| 33 | return privateKey; |
| 34 | } |
| 35 | |
| 36 | @CalledByNative |
| 37 | String getCertificate() { |
| 38 | return certificate; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Generate a new RtcCertificatePem with the default settings of KeyType = ECDSA and |
| 43 | * expires = 30 days. |
| 44 | */ |
| 45 | public static RtcCertificatePem generateCertificate() { |
| 46 | return nativeGenerateCertificate(PeerConnection.KeyType.ECDSA, DEFAULT_EXPIRY); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Generate a new RtcCertificatePem with a custom KeyType and the default setting of |
| 51 | * expires = 30 days. |
| 52 | */ |
| 53 | public static RtcCertificatePem generateCertificate(PeerConnection.KeyType keyType) { |
| 54 | return nativeGenerateCertificate(keyType, DEFAULT_EXPIRY); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Generate a new RtcCertificatePem with a custom expires and the default setting of |
| 59 | * KeyType = ECDSA. |
| 60 | */ |
| 61 | public static RtcCertificatePem generateCertificate(long expires) { |
| 62 | return nativeGenerateCertificate(PeerConnection.KeyType.ECDSA, expires); |
| 63 | } |
| 64 | |
| 65 | /** Generate a new RtcCertificatePem with a custom KeyType and a custom expires. */ |
| 66 | public static RtcCertificatePem generateCertificate( |
| 67 | PeerConnection.KeyType keyType, long expires) { |
| 68 | return nativeGenerateCertificate(keyType, expires); |
| 69 | } |
| 70 | |
| 71 | private static native RtcCertificatePem nativeGenerateCertificate( |
| 72 | PeerConnection.KeyType keyType, long expires); |
| 73 | } |