diff --git a/FirebaseAdmin/FirebaseAdmin/Auth/FirebaseTokenVerifier.cs b/FirebaseAdmin/FirebaseAdmin/Auth/FirebaseTokenVerifier.cs index 4e0c55d1..210b8767 100644 --- a/FirebaseAdmin/FirebaseAdmin/Auth/FirebaseTokenVerifier.cs +++ b/FirebaseAdmin/FirebaseAdmin/Auth/FirebaseTokenVerifier.cs @@ -40,6 +40,9 @@ internal sealed class FirebaseTokenVerifier private static readonly IReadOnlyList StandardClaims = ImmutableList.Create("iss", "aud", "exp", "iat", "sub", "uid"); + // See http://oid-info.com/get/2.16.840.1.101.3.4.2.1 + private const string Sha256Oid = "2.16.840.1.101.3.4.2.1"; + public string ProjectId { get; } private readonly string _shortName; private readonly string _articledShortName; @@ -172,8 +175,17 @@ private async Task VerifySignatureAsync( var keys = await _keySource.GetPublicKeysAsync(cancellationToken) .ConfigureAwait(false); var verified = keys.Any(key => - key.Id == keyId && key.RSA.VerifyHash( - hash, signature, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1)); + { +#if NETSTANDARD1_5 || NETSTANDARD2_0 + return key.Id == keyId && key.RSA.VerifyHash( + hash, signature, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1); +#elif NET45 + return key.Id == keyId && + ((RSACryptoServiceProvider) key.RSA).VerifyHash(hash, Sha256Oid, signature); +#else +#error Unsupported target +#endif + }); if (!verified) { throw new FirebaseException($"Failed to verify {_shortName} signature."); diff --git a/FirebaseAdmin/FirebaseAdmin/Auth/HttpPublicKeySource.cs b/FirebaseAdmin/FirebaseAdmin/Auth/HttpPublicKeySource.cs index 1d1f77a3..4ddd0abf 100644 --- a/FirebaseAdmin/FirebaseAdmin/Auth/HttpPublicKeySource.cs +++ b/FirebaseAdmin/FirebaseAdmin/Auth/HttpPublicKeySource.cs @@ -26,6 +26,14 @@ using Google.Apis.Http; using Google.Apis.Util; +#if NETSTANDARD1_5 || NETSTANDARD2_0 +using RsaKey = System.Security.Cryptography.RSA; +#elif NET45 +using RsaKey = System.Security.Cryptography.RSACryptoServiceProvider; +#else +#error Unsupported target +#endif + namespace FirebaseAdmin.Auth { /// @@ -104,7 +112,14 @@ private IReadOnlyList ParseKeys(string json) foreach (var entry in rawKeys) { var x509cert = new X509Certificate2(Encoding.UTF8.GetBytes(entry.Value)); - var rsa = x509cert.GetRSAPublicKey(); + RsaKey rsa; +#if NETSTANDARD1_5 || NETSTANDARD2_0 + rsa = x509cert.GetRSAPublicKey(); +#elif NET45 + rsa = (RSACryptoServiceProvider) x509cert.PublicKey.Key; +#else +#error Unsupported target +#endif builder.Add(new PublicKey(entry.Key, rsa)); } return builder.ToImmutableList(); diff --git a/FirebaseAdmin/FirebaseAdmin/Auth/PublicKey.cs b/FirebaseAdmin/FirebaseAdmin/Auth/PublicKey.cs index d6639765..158d7e0f 100644 --- a/FirebaseAdmin/FirebaseAdmin/Auth/PublicKey.cs +++ b/FirebaseAdmin/FirebaseAdmin/Auth/PublicKey.cs @@ -12,7 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -using System.Security.Cryptography; +#if NETSTANDARD1_5 || NETSTANDARD2_0 +using RsaKey = System.Security.Cryptography.RSA; +#elif NET45 +using RsaKey = System.Security.Cryptography.RSACryptoServiceProvider; +#else +#error Unsupported target +#endif namespace FirebaseAdmin.Auth { @@ -30,9 +36,9 @@ internal sealed class PublicKey /// A instance containing the contents of /// the public key. /// - public RSA RSA { get; } + public RsaKey RSA { get; } - public PublicKey(string keyId, RSA rsa) + public PublicKey(string keyId, RsaKey rsa) { Id = keyId; RSA = rsa; diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 00000000..a98bb516 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,24 @@ +version: '1.0.{build}' +image: + - Visual Studio 2017 + - Ubuntu +init: + # Good practise, because Windows line endings are different from Unix/Linux ones + - cmd: git config --global core.autocrlf true +install: + # Install repo specific stuff here +before_build: + # Display .NET Core version + - dotnet --version + # Display minimal restore text + - dotnet restore FirebaseAdmin/FirebaseAdmin.sln --verbosity m +build_script: + - dotnet build FirebaseAdmin +after_build: + # For once the build has completed +clone_depth: 1 +test_script: + - dotnet test FirebaseAdmin/FirebaseAdmin.Tests +on_finish : + # any cleanup in here +deploy: off \ No newline at end of file