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#import <Foundation/Foundation.h> 12 13#include <vector> 14 15#include "rtc_base/gunit.h" 16 17#import "api/peerconnection/RTCConfiguration+Private.h" 18#import "api/peerconnection/RTCConfiguration.h" 19#import "api/peerconnection/RTCIceServer.h" 20#import "api/peerconnection/RTCMediaConstraints.h" 21#import "api/peerconnection/RTCPeerConnection.h" 22#import "api/peerconnection/RTCPeerConnectionFactory.h" 23#import "helpers/NSString+StdString.h" 24 25@interface RTCCertificateTest : NSObject 26- (void)testCertificateIsUsedInConfig; 27@end 28 29@implementation RTCCertificateTest 30 31- (void)testCertificateIsUsedInConfig { 32 RTC_OBJC_TYPE(RTCConfiguration) *originalConfig = [[RTC_OBJC_TYPE(RTCConfiguration) alloc] init]; 33 34 NSArray *urlStrings = @[ @"stun:stun1.example.net" ]; 35 RTC_OBJC_TYPE(RTCIceServer) *server = 36 [[RTC_OBJC_TYPE(RTCIceServer) alloc] initWithURLStrings:urlStrings]; 37 originalConfig.iceServers = @[ server ]; 38 39 // Generate a new certificate. 40 RTC_OBJC_TYPE(RTCCertificate) *originalCertificate = [RTC_OBJC_TYPE(RTCCertificate) 41 generateCertificateWithParams:@{@"expires" : @100000, @"name" : @"RSASSA-PKCS1-v1_5"}]; 42 43 // Store certificate in configuration. 44 originalConfig.certificate = originalCertificate; 45 46 RTC_OBJC_TYPE(RTCMediaConstraints) *contraints = 47 [[RTC_OBJC_TYPE(RTCMediaConstraints) alloc] initWithMandatoryConstraints:@{} 48 optionalConstraints:nil]; 49 RTC_OBJC_TYPE(RTCPeerConnectionFactory) *factory = 50 [[RTC_OBJC_TYPE(RTCPeerConnectionFactory) alloc] init]; 51 52 // Create PeerConnection with this certificate. 53 RTC_OBJC_TYPE(RTCPeerConnection) *peerConnection = 54 [factory peerConnectionWithConfiguration:originalConfig constraints:contraints delegate:nil]; 55 56 // Retrieve certificate from the configuration. 57 RTC_OBJC_TYPE(RTCConfiguration) *retrievedConfig = peerConnection.configuration; 58 59 // Extract PEM strings from original certificate. 60 std::string originalPrivateKeyField = [[originalCertificate private_key] UTF8String]; 61 std::string originalCertificateField = [[originalCertificate certificate] UTF8String]; 62 63 // Extract PEM strings from certificate retrieved from configuration. 64 RTC_OBJC_TYPE(RTCCertificate) *retrievedCertificate = retrievedConfig.certificate; 65 std::string retrievedPrivateKeyField = [[retrievedCertificate private_key] UTF8String]; 66 std::string retrievedCertificateField = [[retrievedCertificate certificate] UTF8String]; 67 68 // Check that the original certificate and retrieved certificate match. 69 EXPECT_EQ(originalPrivateKeyField, retrievedPrivateKeyField); 70 EXPECT_EQ(retrievedCertificateField, retrievedCertificateField); 71} 72 73@end 74 75TEST(CertificateTest, DISABLED_CertificateIsUsedInConfig) { 76 RTCCertificateTest *test = [[RTCCertificateTest alloc] init]; 77 [test testCertificateIsUsedInConfig]; 78} 79