|
|
@ -80,18 +80,26 @@ namespace Grpc.Core |
|
|
|
{ |
|
|
|
{ |
|
|
|
readonly IList<KeyCertificatePair> keyCertificatePairs; |
|
|
|
readonly IList<KeyCertificatePair> keyCertificatePairs; |
|
|
|
readonly string rootCertificates; |
|
|
|
readonly string rootCertificates; |
|
|
|
|
|
|
|
readonly bool forceClientAuth; |
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// Creates server-side SSL credentials. |
|
|
|
/// Creates server-side SSL credentials. |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
/// <param name="rootCertificates">PEM encoded client root certificates used to authenticate client.</param> |
|
|
|
|
|
|
|
/// <param name="keyCertificatePairs">Key-certificates to use.</param> |
|
|
|
/// <param name="keyCertificatePairs">Key-certificates to use.</param> |
|
|
|
public SslServerCredentials(IEnumerable<KeyCertificatePair> keyCertificatePairs, string rootCertificates) |
|
|
|
/// <param name="rootCertificates">PEM encoded client root certificates used to authenticate client.</param> |
|
|
|
|
|
|
|
/// <param name="forceClientAuth">If true, client will be rejected unless it proves its unthenticity using against rootCertificates.</param> |
|
|
|
|
|
|
|
public SslServerCredentials(IEnumerable<KeyCertificatePair> keyCertificatePairs, string rootCertificates, bool forceClientAuth) |
|
|
|
{ |
|
|
|
{ |
|
|
|
this.keyCertificatePairs = new List<KeyCertificatePair>(keyCertificatePairs).AsReadOnly(); |
|
|
|
this.keyCertificatePairs = new List<KeyCertificatePair>(keyCertificatePairs).AsReadOnly(); |
|
|
|
Preconditions.CheckArgument(this.keyCertificatePairs.Count > 0, |
|
|
|
Preconditions.CheckArgument(this.keyCertificatePairs.Count > 0, |
|
|
|
"At least one KeyCertificatePair needs to be provided"); |
|
|
|
"At least one KeyCertificatePair needs to be provided"); |
|
|
|
|
|
|
|
if (forceClientAuth) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Preconditions.CheckNotNull(rootCertificates, |
|
|
|
|
|
|
|
"Cannot force client authentication unless you provide rootCertificates."); |
|
|
|
|
|
|
|
} |
|
|
|
this.rootCertificates = rootCertificates; |
|
|
|
this.rootCertificates = rootCertificates; |
|
|
|
|
|
|
|
this.forceClientAuth = forceClientAuth; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
@ -100,7 +108,7 @@ namespace Grpc.Core |
|
|
|
/// using client root certificates. |
|
|
|
/// using client root certificates. |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
/// <param name="keyCertificatePairs">Key-certificates to use.</param> |
|
|
|
/// <param name="keyCertificatePairs">Key-certificates to use.</param> |
|
|
|
public SslServerCredentials(IEnumerable<KeyCertificatePair> keyCertificatePairs) : this(keyCertificatePairs, null) |
|
|
|
public SslServerCredentials(IEnumerable<KeyCertificatePair> keyCertificatePairs) : this(keyCertificatePairs, null, false) |
|
|
|
{ |
|
|
|
{ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -126,6 +134,17 @@ namespace Grpc.Core |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// If true, the authenticity of client check will be enforced. |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
|
|
|
|
public bool ForceClientAuthentication |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
get |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return this.forceClientAuth; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
internal override ServerCredentialsSafeHandle ToNativeCredentials() |
|
|
|
internal override ServerCredentialsSafeHandle ToNativeCredentials() |
|
|
|
{ |
|
|
|
{ |
|
|
|
int count = keyCertificatePairs.Count; |
|
|
|
int count = keyCertificatePairs.Count; |
|
|
@ -136,7 +155,7 @@ namespace Grpc.Core |
|
|
|
certChains[i] = keyCertificatePairs[i].CertificateChain; |
|
|
|
certChains[i] = keyCertificatePairs[i].CertificateChain; |
|
|
|
keys[i] = keyCertificatePairs[i].PrivateKey; |
|
|
|
keys[i] = keyCertificatePairs[i].PrivateKey; |
|
|
|
} |
|
|
|
} |
|
|
|
return ServerCredentialsSafeHandle.CreateSslCredentials(rootCertificates, certChains, keys); |
|
|
|
return ServerCredentialsSafeHandle.CreateSslCredentials(rootCertificates, certChains, keys, forceClientAuth); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|