Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions FirebaseAdmin/FirebaseAdmin/Auth/FirebaseTokenVerifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ internal sealed class FirebaseTokenVerifier
private static readonly IReadOnlyList<string> StandardClaims =
ImmutableList.Create<string>("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;
Expand Down Expand Up @@ -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.");
Expand Down
17 changes: 16 additions & 1 deletion FirebaseAdmin/FirebaseAdmin/Auth/HttpPublicKeySource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
/// <summary>
Expand Down Expand Up @@ -104,7 +112,14 @@ private IReadOnlyList<PublicKey> 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();
Expand Down
12 changes: 9 additions & 3 deletions FirebaseAdmin/FirebaseAdmin/Auth/PublicKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -30,9 +36,9 @@ internal sealed class PublicKey
/// A <see cref="System.Security.Cryptography.RSA"/> instance containing the contents of
/// the public key.
/// </summary>
public RSA RSA { get; }
public RsaKey RSA { get; }

public PublicKey(string keyId, RSA rsa)
public PublicKey(string keyId, RsaKey rsa)
{
Id = keyId;
RSA = rsa;
Expand Down
24 changes: 24 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -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