Skip to content
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
2 changes: 1 addition & 1 deletion .codegen.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "engineHash": "12f2054", "specHash": "5bf3652", "version": "0.1.0" }
{ "engineHash": "205c0e9", "specHash": "5bf3652", "version": "0.1.0" }
14 changes: 14 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
blank_issues_enabled: false
contact_links:
- name: SDK documentation
url: https://github.com/box/box-windows-sdk-v2/tree/sdk-gen/docs
about: Before creating an issue, I have checked that the SDK documentation doesn't solve my issue.
- name: API documentation
url: https://developer.box.com/docs
about: Before creating an issue, I have checked that the API documentation doesn't solve my issue.
- name: Box Developer Forums
url: https://community.box.com/box-platform-5
about: Before creating an issue, I have searched the Box Developer Forums and my issue isn't already reported there.
- name: Issues in this repo
url: https://github.com/box/box-windows-sdk-v2/search?type=Issues
about: Before creating an issue, I have searched Issues in this repo and my issue isn't already reported.
2 changes: 1 addition & 1 deletion .github/workflows/autoupdate-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Autoupdate PR
on:
push:
branches:
- main
- sdk-gen

jobs:
update_pull_requests:
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ name: build-and-test
on:
pull_request:
branches:
- main
- sdk-gen
push:
branches:
- main

- sdk-gen
jobs:
build-and-test:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/notify-changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ jobs:
token: ${{ secrets.DISPATCH_ACCESS_TOKEN }}
repository: box/box-developer-changelog
event-type: new-release-note
client-payload: '{"ref": "${{ github.ref }}", "repository": "${{github.repository}}", "labels": "sdks,dotnet", "repo_display_name": "Box Dotnet SDK Generated"}'
client-payload: '{"ref": "${{ github.ref }}", "repository": "${{github.repository}}", "labels": "sdks,dotnet", "repo_display_name": "Box Windows SDK"}'
2 changes: 2 additions & 0 deletions .github/workflows/semantic-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ on:
- opened
- edited
- synchronize
branches:
- sdk-gen

jobs:
main:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/spell-check-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
pull_request_target:
types: [opened, synchronize, edited]
branches:
- main
- sdk-gen
jobs:
spellcheck-request:
runs-on: ubuntu-latest
Expand Down
28 changes: 28 additions & 0 deletions Box.Sdk.Gen.Net/Box.Sdk.Gen.Net.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Version>0.1.0</Version>
<Description>Official Box .Net Generated SDK</Description>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<Nullable>enable</Nullable>
<isPackable>true</isPackable>
<PackageId>Box.Sdk.Gen.Net</PackageId>
</PropertyGroup>


<ItemGroup>
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.12.1" />
<PackageReference Include="System.Text.Json" Version="8.0.5" />
<PackageReference Include="BouncyCastle.Cryptography" Version="2.6.1" />
<PackageReference Include="BouncyCastle.Cryptography" Version="2.6.1" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
</ItemGroup>


<ItemGroup>
<InternalsVisibleTo Include="Box.Sdk.Gen.Tests.Integration.Net"/>
</ItemGroup>

</Project>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
106 changes: 106 additions & 0 deletions Box.Sdk.Gen.Net/Internal/DefaultPrivateKeyDecryptor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
using System;
using System.IO;
using System.Security.Cryptography;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.OpenSsl;
using Org.BouncyCastle.Math;

namespace Box.Sdk.Gen
{
internal class DefaultPrivateKeyDecryptor : IPrivateKeyDecryptor
{
internal DefaultPrivateKeyDecryptor()
{
}

/// <summary>
/// Decrypts private key using a passphrase.
/// </summary>
public RSA DecryptPrivateKey(string encryptedPrivateKey, string passphrase)
{
var pwf = new PEMPasswordFinder(passphrase);

object? privateKey = null;

using (var reader = new StringReader(encryptedPrivateKey))
{
privateKey = new PemReader(reader, pwf).ReadObject();
}

if (privateKey == null)
{
throw new Exception("Invalid private JWT key!");
}

RSA? rsa = null;
if (privateKey is AsymmetricCipherKeyPair)
{
var ackp = (AsymmetricCipherKeyPair)privateKey;

rsa = ToRSA((RsaPrivateCrtKeyParameters)ackp.Private);
}
else if (privateKey is RsaPrivateCrtKeyParameters)
{
rsa = ToRSA((RsaPrivateCrtKeyParameters)privateKey);
}

if (rsa == null)
{
throw new Exception("Private key is null");
}

return rsa;
}

private static RSA ToRSA(RsaPrivateCrtKeyParameters privateKeyParameters)
{
var rsaParameters = ToRSAParameters(privateKeyParameters);
var rsa = RSA.Create();
rsa.ImportParameters(rsaParameters);

return rsa;
}

private static RSAParameters ToRSAParameters(RsaPrivateCrtKeyParameters privKey)
{
var rp = new RSAParameters
{
Modulus = privKey.Modulus.ToByteArrayUnsigned(),
Exponent = privKey.PublicExponent.ToByteArrayUnsigned(),
P = privKey.P.ToByteArrayUnsigned(),
Q = privKey.Q.ToByteArrayUnsigned()
};
rp.D = ConvertRSAParametersField(privKey.Exponent, rp.Modulus.Length);
rp.DP = ConvertRSAParametersField(privKey.DP, rp.P.Length);
rp.DQ = ConvertRSAParametersField(privKey.DQ, rp.Q.Length);
rp.InverseQ = ConvertRSAParametersField(privKey.QInv, rp.Q.Length);
return rp;
}

private static byte[] ConvertRSAParametersField(BigInteger n, int size)
{
byte[] bs = n.ToByteArrayUnsigned();
if (bs.Length == size)
{
return bs;
}

if (bs.Length > size)
{
throw new ArgumentException("Specified size too small", "size");
}

byte[] padded = new byte[size];
Array.Copy(bs, 0, padded, size - bs.Length, bs.Length);
return padded;
}
}

internal class PEMPasswordFinder : IPasswordFinder
{
private readonly string _pword;
public PEMPasswordFinder(string password) { _pword = password; }
public char[] GetPassword() { return _pword.ToCharArray(); }
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading
Loading