Code re-factorings and formatting for Basket.API project
This commit is contained in:
parent
386c118616
commit
d44c12e718
@ -2998,12 +2998,10 @@ function pkcs1pad2(s,n) {
|
||||
}
|
||||
|
||||
// PKCS#1 (OAEP) mask generation function
|
||||
function oaep_mgf1_arr(seed, len, hash)
|
||||
{
|
||||
function oaep_mgf1_arr(seed, len, hash) {
|
||||
var mask = '', i = 0;
|
||||
|
||||
while (mask.length < len)
|
||||
{
|
||||
while (mask.length < len) {
|
||||
mask += hash(String.fromCharCode.apply(String, seed.concat([
|
||||
(i & 0xff000000) >> 24,
|
||||
(i & 0x00ff0000) >> 16,
|
||||
@ -3018,17 +3016,14 @@ function oaep_mgf1_arr(seed, len, hash)
|
||||
var SHA1_SIZE = 20;
|
||||
|
||||
// PKCS#1 (OAEP) pad input string s to n bytes, and return a bigint
|
||||
function oaep_pad(s, n, hash)
|
||||
{
|
||||
if (s.length + 2 * SHA1_SIZE + 2 > n)
|
||||
{
|
||||
function oaep_pad(s, n, hash) {
|
||||
if (s.length + 2 * SHA1_SIZE + 2 > n) {
|
||||
throw "Message too long for RSA";
|
||||
}
|
||||
|
||||
var PS = '', i;
|
||||
|
||||
for (i = 0; i < n - s.length - 2 * SHA1_SIZE - 2; i += 1)
|
||||
{
|
||||
for (i = 0; i < n - s.length - 2 * SHA1_SIZE - 2; i += 1) {
|
||||
PS += '\x00';
|
||||
}
|
||||
|
||||
@ -3039,16 +3034,14 @@ function oaep_pad(s, n, hash)
|
||||
var dbMask = oaep_mgf1_arr(seed, DB.length, hash || rstr_sha1);
|
||||
var maskedDB = [];
|
||||
|
||||
for (i = 0; i < DB.length; i += 1)
|
||||
{
|
||||
for (i = 0; i < DB.length; i += 1) {
|
||||
maskedDB[i] = DB.charCodeAt(i) ^ dbMask.charCodeAt(i);
|
||||
}
|
||||
|
||||
var seedMask = oaep_mgf1_arr(maskedDB, seed.length, rstr_sha1);
|
||||
var maskedSeed = [0];
|
||||
|
||||
for (i = 0; i < seed.length; i += 1)
|
||||
{
|
||||
for (i = 0; i < seed.length; i += 1) {
|
||||
maskedSeed[i + 1] = seed[i] ^ seedMask.charCodeAt(i);
|
||||
}
|
||||
|
||||
@ -3070,8 +3063,7 @@ function RSAKey() {
|
||||
// Set the public key fields N and e from hex strings
|
||||
function RSASetPublic(N, E) {
|
||||
this.isPublic = true;
|
||||
if (typeof N !== "string")
|
||||
{
|
||||
if (typeof N !== "string") {
|
||||
this.n = N;
|
||||
this.e = E;
|
||||
}
|
||||
@ -3159,12 +3151,10 @@ function pkcs1unpad2(d,n) {
|
||||
}
|
||||
|
||||
// PKCS#1 (OAEP) mask generation function
|
||||
function oaep_mgf1_str(seed, len, hash)
|
||||
{
|
||||
function oaep_mgf1_str(seed, len, hash) {
|
||||
var mask = '', i = 0;
|
||||
|
||||
while (mask.length < len)
|
||||
{
|
||||
while (mask.length < len) {
|
||||
mask += hash(seed + String.fromCharCode.apply(String, [
|
||||
(i & 0xff000000) >> 24,
|
||||
(i & 0x00ff0000) >> 16,
|
||||
@ -3179,26 +3169,22 @@ function oaep_mgf1_str(seed, len, hash)
|
||||
var SHA1_SIZE = 20;
|
||||
|
||||
// Undo PKCS#1 (OAEP) padding and, if valid, return the plaintext
|
||||
function oaep_unpad(d, n, hash)
|
||||
{
|
||||
function oaep_unpad(d, n, hash) {
|
||||
d = d.toByteArray();
|
||||
|
||||
var i;
|
||||
|
||||
for (i = 0; i < d.length; i += 1)
|
||||
{
|
||||
for (i = 0; i < d.length; i += 1) {
|
||||
d[i] &= 0xff;
|
||||
}
|
||||
|
||||
while (d.length < n)
|
||||
{
|
||||
while (d.length < n) {
|
||||
d.unshift(0);
|
||||
}
|
||||
|
||||
d = String.fromCharCode.apply(String, d);
|
||||
|
||||
if (d.length < 2 * SHA1_SIZE + 2)
|
||||
{
|
||||
if (d.length < 2 * SHA1_SIZE + 2) {
|
||||
throw "Cipher too short";
|
||||
}
|
||||
|
||||
@ -3208,8 +3194,7 @@ function oaep_unpad(d, n, hash)
|
||||
var seedMask = oaep_mgf1_str(maskedDB, SHA1_SIZE, hash || rstr_sha1);
|
||||
var seed = [], i;
|
||||
|
||||
for (i = 0; i < maskedSeed.length; i += 1)
|
||||
{
|
||||
for (i = 0; i < maskedSeed.length; i += 1) {
|
||||
seed[i] = maskedSeed.charCodeAt(i) ^ seedMask.charCodeAt(i);
|
||||
}
|
||||
|
||||
@ -3218,15 +3203,13 @@ function oaep_unpad(d, n, hash)
|
||||
|
||||
var DB = [];
|
||||
|
||||
for (i = 0; i < maskedDB.length; i += 1)
|
||||
{
|
||||
for (i = 0; i < maskedDB.length; i += 1) {
|
||||
DB[i] = maskedDB.charCodeAt(i) ^ dbMask.charCodeAt(i);
|
||||
}
|
||||
|
||||
DB = String.fromCharCode.apply(String, DB);
|
||||
|
||||
if (DB.substr(0, SHA1_SIZE) !== rstr_sha1(''))
|
||||
{
|
||||
if (DB.substr(0, SHA1_SIZE) !== rstr_sha1('')) {
|
||||
throw "Hash mismatch";
|
||||
}
|
||||
|
||||
@ -3235,8 +3218,7 @@ function oaep_unpad(d, n, hash)
|
||||
var first_one = DB.indexOf('\x01');
|
||||
var last_zero = (first_one != -1) ? DB.substr(0, first_one).lastIndexOf('\x00') : -1;
|
||||
|
||||
if (last_zero + 1 != first_one)
|
||||
{
|
||||
if (last_zero + 1 != first_one) {
|
||||
throw "Malformed data";
|
||||
}
|
||||
|
||||
@ -3246,8 +3228,7 @@ function oaep_unpad(d, n, hash)
|
||||
// Set the private key fields N, e, and d from hex strings
|
||||
function RSASetPrivate(N, E, D) {
|
||||
this.isPrivate = true;
|
||||
if (typeof N !== "string")
|
||||
{
|
||||
if (typeof N !== "string") {
|
||||
this.n = N;
|
||||
this.e = E;
|
||||
this.d = D;
|
||||
@ -5504,20 +5485,16 @@ function b64utohex(s) {
|
||||
|
||||
var utf8tob64u, b64utoutf8;
|
||||
|
||||
if (typeof Buffer === 'function')
|
||||
{
|
||||
utf8tob64u = function (s)
|
||||
{
|
||||
if (typeof Buffer === 'function') {
|
||||
utf8tob64u = function (s) {
|
||||
return b64tob64u(new Buffer(s, 'utf8').toString('base64'));
|
||||
};
|
||||
|
||||
b64utoutf8 = function (s)
|
||||
{
|
||||
b64utoutf8 = function (s) {
|
||||
return new Buffer(b64utob64(s), 'base64').toString('utf8');
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
// ==== utf8 / base64url ================================
|
||||
/**
|
||||
* convert a UTF-8 encoded string including CJK or Latin to a Base64URL encoded string.<br/>
|
||||
@ -5525,8 +5502,7 @@ else
|
||||
* @return {String} Base64URL encoded string
|
||||
* @since 1.1
|
||||
*/
|
||||
utf8tob64u = function (s)
|
||||
{
|
||||
utf8tob64u = function (s) {
|
||||
return hextob64u(uricmptohex(encodeURIComponentAll(s)));
|
||||
};
|
||||
|
||||
@ -5536,8 +5512,7 @@ else
|
||||
* @return {String} UTF-8 encoded string
|
||||
* @since 1.1
|
||||
*/
|
||||
b64utoutf8 = function (s)
|
||||
{
|
||||
b64utoutf8 = function (s) {
|
||||
return decodeURIComponent(hextouricmp(b64utohex(s)));
|
||||
};
|
||||
}
|
||||
|
@ -17,7 +17,9 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Auth.Server
|
||||
if (isAuthorized && !allowAnonymous)
|
||||
{
|
||||
if (operation.Parameters == null)
|
||||
{
|
||||
operation.Parameters = new List<IParameter>();
|
||||
}
|
||||
|
||||
operation.Parameters.Add(new NonBodyParameter
|
||||
{
|
||||
|
@ -6,8 +6,6 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers
|
||||
{
|
||||
// GET: /<controller>/
|
||||
public IActionResult Index()
|
||||
{
|
||||
return new RedirectResult("~/swagger");
|
||||
}
|
||||
=> new RedirectResult("~/swagger");
|
||||
}
|
||||
}
|
||||
|
@ -7,8 +7,6 @@ namespace Basket.API.Infrastructure.ActionResults
|
||||
{
|
||||
public InternalServerErrorObjectResult(object error)
|
||||
: base(error)
|
||||
{
|
||||
StatusCode = StatusCodes.Status500InternalServerError;
|
||||
}
|
||||
=> StatusCode = StatusCodes.Status500InternalServerError;
|
||||
}
|
||||
}
|
||||
|
@ -6,9 +6,7 @@ namespace Basket.API.Infrastructure.Middlewares
|
||||
public static class FailingMiddlewareAppBuilderExtensions
|
||||
{
|
||||
public static IApplicationBuilder UseFailingMiddleware(this IApplicationBuilder builder)
|
||||
{
|
||||
return UseFailingMiddleware(builder, null);
|
||||
}
|
||||
=> UseFailingMiddleware(builder, null);
|
||||
public static IApplicationBuilder UseFailingMiddleware(this IApplicationBuilder builder, Action<FailingOptions> action)
|
||||
{
|
||||
var options = new FailingOptions();
|
||||
|
@ -1,7 +1,6 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -1,20 +1,26 @@
|
||||
using Basket.API.Infrastructure.Middlewares;
|
||||
using Microsoft.AspNetCore;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.IO;
|
||||
using static Microsoft.AspNetCore.Hosting.ApplicationInsightsWebHostBuilderExtensions;
|
||||
using static Microsoft.AspNetCore.Hosting.HealthCheckWebHostBuilderExtension;
|
||||
using static Microsoft.AspNetCore.Hosting.HostingAbstractionsWebHostBuilderExtensions;
|
||||
using static Microsoft.AspNetCore.Hosting.WebHostBuilderExtensions;
|
||||
using static Microsoft.AspNetCore.Hosting.WebHostExtensions;
|
||||
using static Microsoft.Extensions.Configuration.AzureKeyVaultConfigurationExtensions;
|
||||
using static Microsoft.Extensions.Configuration.ChainedBuilderExtensions;
|
||||
using static Microsoft.Extensions.Configuration.EnvironmentVariablesExtensions;
|
||||
using ConfigurationBuilder = Microsoft.Extensions.Configuration.ConfigurationBuilder;
|
||||
using Convert = System.Convert;
|
||||
using Directory = System.IO.Directory;
|
||||
using IWebHost = Microsoft.AspNetCore.Hosting.IWebHost;
|
||||
using WebHost = Microsoft.AspNetCore.WebHost;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Services.Basket.API
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
BuildWebHost(args).Run();
|
||||
}
|
||||
=> BuildWebHost(args).Run();
|
||||
|
||||
public static IWebHost BuildWebHost(string[] args) =>
|
||||
WebHost.CreateDefaultBuilder(args)
|
||||
|
@ -50,12 +50,14 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
|
||||
RegisterAppInsights(services);
|
||||
|
||||
// Add framework services.
|
||||
services.AddMvc(options =>
|
||||
services
|
||||
.AddMvc(options =>
|
||||
{
|
||||
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
|
||||
options.Filters.Add(typeof(ValidateModelStateFilter));
|
||||
|
||||
}).AddControllersAsServices();
|
||||
})
|
||||
.AddControllersAsServices();
|
||||
|
||||
ConfigureAuthService(services);
|
||||
|
||||
@ -74,7 +76,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
|
||||
//and then creating the connection it seems reasonable to move
|
||||
//that cost to startup instead of having the first request pay the
|
||||
//penalty.
|
||||
services.AddSingleton<ConnectionMultiplexer>(sp =>
|
||||
services.AddSingleton(sp =>
|
||||
{
|
||||
var settings = sp.GetRequiredService<IOptions<BasketSettings>>().Value;
|
||||
var configuration = ConfigurationOptions.Parse(settings.ConnectionString, true);
|
||||
@ -238,12 +240,14 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
|
||||
|
||||
var identityUrl = Configuration.GetValue<string>("IdentityUrl");
|
||||
|
||||
services.AddAuthentication(options =>
|
||||
services
|
||||
.AddAuthentication(options =>
|
||||
{
|
||||
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||
|
||||
}).AddJwtBearer(options =>
|
||||
})
|
||||
.AddJwtBearer(options =>
|
||||
{
|
||||
options.Authority = identityUrl;
|
||||
options.RequireHttpsMetadata = false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user