blob: 6070135b3e12f27ef753596b45f9ce9ddf9415f0 [file] [log] [blame]
Michael Iedema02137862018-10-09 15:30:01 +02001/*
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
11package org.webrtc;
12
Patrik Höglundbd6ffaf2018-11-16 14:55:16 +010013import org.webrtc.PeerConnection;
14
Michael Iedema02137862018-10-09 15:30:01 +020015/**
16 * Easily storable/serializable version of a native C++ RTCCertificatePEM.
17 */
18public class RtcCertificatePem {
19 /** PEM string representation of the private key. */
20 public final String privateKey;
21 /** PEM string representation of the certificate. */
22 public final String certificate;
23 /** Default expiration time of 30 days. */
24 private static final long DEFAULT_EXPIRY = 60 * 60 * 24 * 30;
25
26 /** Instantiate an RtcCertificatePem object from stored strings. */
27 @CalledByNative
28 public RtcCertificatePem(String privateKey, String certificate) {
29 this.privateKey = privateKey;
30 this.certificate = certificate;
31 }
32
33 @CalledByNative
34 String getPrivateKey() {
35 return privateKey;
36 }
37
38 @CalledByNative
39 String getCertificate() {
40 return certificate;
41 }
42
43 /**
44 * Generate a new RtcCertificatePem with the default settings of KeyType = ECDSA and
45 * expires = 30 days.
46 */
47 public static RtcCertificatePem generateCertificate() {
48 return nativeGenerateCertificate(PeerConnection.KeyType.ECDSA, DEFAULT_EXPIRY);
49 }
50
51 /**
52 * Generate a new RtcCertificatePem with a custom KeyType and the default setting of
53 * expires = 30 days.
54 */
55 public static RtcCertificatePem generateCertificate(PeerConnection.KeyType keyType) {
56 return nativeGenerateCertificate(keyType, DEFAULT_EXPIRY);
57 }
58
59 /**
60 * Generate a new RtcCertificatePem with a custom expires and the default setting of
61 * KeyType = ECDSA.
62 */
63 public static RtcCertificatePem generateCertificate(long expires) {
64 return nativeGenerateCertificate(PeerConnection.KeyType.ECDSA, expires);
65 }
66
67 /** Generate a new RtcCertificatePem with a custom KeyType and a custom expires. */
68 public static RtcCertificatePem generateCertificate(
69 PeerConnection.KeyType keyType, long expires) {
70 return nativeGenerateCertificate(keyType, expires);
71 }
72
73 private static native RtcCertificatePem nativeGenerateCertificate(
74 PeerConnection.KeyType keyType, long expires);
75}