1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-06 21:48:12 -05:00

Replace OtpSharp with Otp.NET for net core support

This commit is contained in:
Kyle Spearrin 2017-01-13 21:34:54 -05:00
parent 77e54f7c12
commit 1b30a27990
3 changed files with 6 additions and 8 deletions

View File

@ -1,10 +1,9 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Base32;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Bit.Core.Domains; using Bit.Core.Domains;
using Bit.Core.Enums; using Bit.Core.Enums;
using OtpSharp; using OtpNet;
namespace Bit.Core.Identity namespace Bit.Core.Identity
{ {
@ -32,7 +31,7 @@ namespace Bit.Core.Identity
public Task<bool> ValidateAsync(string purpose, string token, UserManager<User> manager, User user) public Task<bool> ValidateAsync(string purpose, string token, UserManager<User> manager, User user)
{ {
var otp = new Totp(Base32Encoder.Decode(user.AuthenticatorKey)); var otp = new Totp(Base32Encoding.ToBytes(user.AuthenticatorKey));
long timeStepMatched; long timeStepMatched;
var valid = otp.VerifyTotp(token, out timeStepMatched, new VerificationWindow(2, 2)); var valid = otp.VerifyTotp(token, out timeStepMatched, new VerificationWindow(2, 2));

View File

@ -6,11 +6,10 @@ using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Bit.Core.Domains; using Bit.Core.Domains;
using Bit.Core.Repositories; using Bit.Core.Repositories;
using OtpSharp;
using Base32;
using System.Linq; using System.Linq;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Bit.Core.Enums; using Bit.Core.Enums;
using OtpNet;
namespace Bit.Core.Services namespace Bit.Core.Services
{ {
@ -252,7 +251,7 @@ namespace Bit.Core.Services
{ {
case Enums.TwoFactorProviderType.Authenticator: case Enums.TwoFactorProviderType.Authenticator:
var key = KeyGeneration.GenerateRandomKey(20); var key = KeyGeneration.GenerateRandomKey(20);
user.AuthenticatorKey = Base32Encoder.Encode(key); user.AuthenticatorKey = Base32Encoding.ToString(key);
break; break;
default: default:
throw new ArgumentException(nameof(provider)); throw new ArgumentException(nameof(provider));

View File

@ -2,7 +2,6 @@
"dependencies": { "dependencies": {
"Microsoft.AspNetCore.Identity": "1.1.0", "Microsoft.AspNetCore.Identity": "1.1.0",
"Microsoft.AspNetCore.Authentication.JwtBearer": "1.1.0", "Microsoft.AspNetCore.Authentication.JwtBearer": "1.1.0",
"OtpSharp": "1.3.0.4",
"Microsoft.AspNetCore.Mvc.Abstractions": "1.1.0", "Microsoft.AspNetCore.Mvc.Abstractions": "1.1.0",
"Dapper": "1.50.2", "Dapper": "1.50.2",
"DataTableProxy": "1.2.0", "DataTableProxy": "1.2.0",
@ -10,7 +9,8 @@
"PushSharp": "4.0.10", "PushSharp": "4.0.10",
"WindowsAzure.Storage": "8.0.0", "WindowsAzure.Storage": "8.0.0",
"IdentityServer4": "1.0.1", "IdentityServer4": "1.0.1",
"IdentityServer4.AccessTokenValidation": "1.0.2" "IdentityServer4.AccessTokenValidation": "1.0.2",
"Otp.NET": "1.0.0"
}, },
"frameworks": { "frameworks": {