Review feedback

pull/15554/head
Konstantin Varlamov 7 years ago
parent a9b235a224
commit e05196d819
  1. 13
      src/objective-c/GRPCClient/private/GRPCHost.m

@ -126,9 +126,10 @@ static NSMutableDictionary *kHostCache;
completionQueue:queue]; completionQueue:queue];
} }
- (NSData *)dataWithNsString:(NSString *)string { - (NSData *)nullTerminatedDataWithString:(NSString *)string {
// dataUsingEncoding: does not return a null-terminated string.
NSData *data = [string dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; NSData *data = [string dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSMutableData *nullTerminated = [NSMutableData dataWithData: data]; NSMutableData *nullTerminated = [NSMutableData dataWithData:data];
[nullTerminated appendBytes:"\0" length:1]; [nullTerminated appendBytes:"\0" length:1];
return nullTerminated; return nullTerminated;
} }
@ -154,12 +155,12 @@ static NSMutableDictionary *kHostCache;
kDefaultRootsError = error; kDefaultRootsError = error;
return; return;
} }
kDefaultRootsASCII = [self dataWithNsString:contentInUTF8]; kDefaultRootsASCII = [self nullTerminatedDataWithString:contentInUTF8];
}); });
NSData *rootsASCII; NSData *rootsASCII;
if (pemRootCerts != nil) { if (pemRootCerts != nil) {
rootsASCII = [self dataWithNsString:pemRootCerts]; rootsASCII = [self nullTerminatedDataWithString:pemRootCerts];
} else { } else {
if (kDefaultRootsASCII == nil) { if (kDefaultRootsASCII == nil) {
if (errorPtr) { if (errorPtr) {
@ -182,8 +183,8 @@ static NSMutableDictionary *kHostCache;
creds = grpc_ssl_credentials_create(rootsASCII.bytes, NULL, NULL); creds = grpc_ssl_credentials_create(rootsASCII.bytes, NULL, NULL);
} else { } else {
grpc_ssl_pem_key_cert_pair key_cert_pair; grpc_ssl_pem_key_cert_pair key_cert_pair;
NSData *privateKeyASCII = [self dataWithNsString:pemPrivateKey]; NSData *privateKeyASCII = [self nullTerminatedDataWithString:pemPrivateKey];
NSData *certChainASCII = [self dataWithNsString:pemCertChain]; NSData *certChainASCII = [self nullTerminatedDataWithString:pemCertChain];
key_cert_pair.private_key = privateKeyASCII.bytes; key_cert_pair.private_key = privateKeyASCII.bytes;
key_cert_pair.cert_chain = certChainASCII.bytes; key_cert_pair.cert_chain = certChainASCII.bytes;
creds = grpc_ssl_credentials_create(rootsASCII.bytes, &key_cert_pair, NULL); creds = grpc_ssl_credentials_create(rootsASCII.bytes, &key_cert_pair, NULL);

Loading…
Cancel
Save