Skip to content

AT Proof-Of-Possession #3: Browser Implementation of token signing and key storage #2154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Sep 2, 2020

Conversation

pkanher617
Copy link
Contributor

This PR is a follow up to PR #2153, and includes the msal-browser implementation of the token signing and key storage APIs introduced in the previous code.

Specifically, this PR includes the following:

  • Browser implementation of key storage using IndexedDB
  • Browser implementation of jwt token signing

@github-actions github-actions bot added the msal-browser Related to msal-browser package label Aug 15, 2020
Copy link
Collaborator

@tnorling tnorling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good. Would like to see tests before hitting approve.

@@ -26,23 +34,20 @@ export class CryptoOps implements ICrypto {
private static EXTRACTABLE: boolean = true;
private static POP_HASH_LENGTH = 43; // 256 bit digest / 6 bits per char = 43

private static DB_VERSION = 1;
private static DB_NAME = "msal.db";
private static TABLE_NAME =`${CryptoOps.DB_NAME}.keys`;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be in constants

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These aren't used outside the context of the crypto APIs, so I chose to keep them here.

/**
* Storage wrapper for IndexedDB storage in browsers: https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API
*/
export class DatabaseStorage<T>{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since someone might want to use IndexedDB as a storage option in the future, should we have this be an implementation of CacheManager? I understand there's complexities around async storage but curious if others think it's worth the investment to figure it out now instead of refactoring later?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think async storage will be a separate discussion. For now I think I will leave this as a specific implementation in our lib.

@pkanher617 pkanher617 changed the base branch from pop-handle-response to pop August 20, 2020 22:12
@pkanher617 pkanher617 changed the base branch from pop to pop-handle-response August 20, 2020 22:13
@pkanher617 pkanher617 changed the base branch from pop-handle-response to pop August 28, 2020 21:23
/**
* Storage wrapper for IndexedDB storage in browsers: https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API
*/
export class DatabaseStorage<T>{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit Pick Could we call this IndexDatabaseStorage to be more specific

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is leaking implementation details, which I think we should avoid doing when naming things when possible.

* @param key
* @param data
*/
async sign(key: CryptoKey, data: ArrayBuffer): Promise<ArrayBuffer> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit pick
I wonder if this could be more specific "signToken"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to keep naming consistent with the browser crypto APIs.

Copy link
Contributor

@jmckennon jmckennon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, one comment

* @param extractable
* @param usages
*/
private async msCryptoImportKey(keyBuffer: ArrayBuffer, extractable: boolean, usages: Array<KeyUsage>): Promise<CryptoKey> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should all of the IE stuff be its own file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can separate it into it's own file for readability, I thought it would be easier to have all the crypto APIs in a single file.

@DarylThayil
Copy link
Contributor

mostly looks good, I was rely on @jasonnutter for final sign off

Copy link
Contributor

@jasonnutter jasonnutter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few things, lgtm otherwise.

* @param key
*/
async get(key: string): Promise<T> {
return new Promise((resolve, reject) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to pass the generic type to the Promise?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

private _db : IDBDatabase;
private _dbName: string;
private _tableName: string;
private _version: number;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should avoid using underscores for private variables.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

this._tableName = tableName;
this._version = version;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about delete?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved offline.

@pkanher617 pkanher617 deleted the pop-browser-sign-token branch October 2, 2020 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-pop msal-browser Related to msal-browser package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants