generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Protocol Interface Permissions (#803)
- add delegateGrant ability to `ProtocolConfigure` - Allow `ProtocolPermissionScope` to be scoped down to a specific protocol - move getAuthor helper from `Record` util class to `Message` core class. When DWAs request permissions, they will now be issued a `ProtocolsQuery` permission scoped to the protocol they are being authorized, as well as optionally a `ProtocolsConfigure` for that protocol. Satisfies: #801 #802
- Loading branch information
1 parent
a5d66bf
commit 080359c
Showing
23 changed files
with
651 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import type { MessageStore } from '../types/message-store.js'; | ||
import type { PermissionGrant } from '../protocols/permission-grant.js'; | ||
import type { ProtocolPermissionScope } from '../types/permission-types.js'; | ||
import type { ProtocolsConfigureMessage, ProtocolsQueryMessage } from '../types/protocols-types.js'; | ||
|
||
import { GrantAuthorization } from './grant-authorization.js'; | ||
import { DwnError, DwnErrorCode } from './dwn-error.js'; | ||
|
||
export class ProtocolsGrantAuthorization { | ||
/** | ||
* Authorizes the given ProtocolsConfigure in the scope of the DID given. | ||
*/ | ||
public static async authorizeConfigure(input: { | ||
protocolsConfigureMessage: ProtocolsConfigureMessage, | ||
expectedGrantor: string, | ||
expectedGrantee: string, | ||
permissionGrant: PermissionGrant, | ||
messageStore: MessageStore, | ||
}): Promise<void> { | ||
const { | ||
protocolsConfigureMessage, expectedGrantor, expectedGrantee, permissionGrant, messageStore | ||
} = input; | ||
|
||
await GrantAuthorization.performBaseValidation({ | ||
incomingMessage: protocolsConfigureMessage, | ||
expectedGrantor, | ||
expectedGrantee, | ||
permissionGrant, | ||
messageStore | ||
}); | ||
|
||
ProtocolsGrantAuthorization.verifyScope(protocolsConfigureMessage, permissionGrant.scope as ProtocolPermissionScope); | ||
} | ||
|
||
/** | ||
* Authorizes the scope of a permission grant for a ProtocolsQuery message. | ||
* @param messageStore Used to check if the grant has been revoked. | ||
*/ | ||
public static async authorizeQuery(input: { | ||
expectedGrantor: string, | ||
expectedGrantee: string, | ||
incomingMessage: ProtocolsQueryMessage; | ||
permissionGrant: PermissionGrant; | ||
messageStore: MessageStore; | ||
}): Promise<void> { | ||
const { expectedGrantee, expectedGrantor, incomingMessage, permissionGrant, messageStore } = input; | ||
|
||
await GrantAuthorization.performBaseValidation({ | ||
incomingMessage: incomingMessage, | ||
expectedGrantor, | ||
expectedGrantee, | ||
permissionGrant, | ||
messageStore | ||
}); | ||
|
||
// If the grant specifies a protocol, the query must specify the same protocol. | ||
const permissionScope = permissionGrant.scope as ProtocolPermissionScope; | ||
const protocolInGrant = permissionScope.protocol; | ||
const protocolInMessage = incomingMessage.descriptor.filter?.protocol; | ||
if (protocolInGrant !== undefined && protocolInMessage !== protocolInGrant) { | ||
throw new DwnError( | ||
DwnErrorCode.ProtocolsGrantAuthorizationQueryProtocolScopeMismatch, | ||
`Grant protocol scope ${protocolInGrant} does not match protocol in message ${protocolInMessage}` | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* Verifies a ProtocolsConfigure against the scope of the given grant. | ||
*/ | ||
private static verifyScope( | ||
protocolsConfigureMessage: ProtocolsConfigureMessage, | ||
grantScope: ProtocolPermissionScope | ||
): void { | ||
|
||
// if the grant scope does not specify a protocol, then it is am unrestricted grant | ||
if (grantScope.protocol === undefined) { | ||
return; | ||
} | ||
|
||
if (grantScope.protocol !== protocolsConfigureMessage.descriptor.definition.protocol) { | ||
throw new DwnError( | ||
DwnErrorCode.ProtocolsGrantAuthorizationScopeProtocolMismatch, | ||
`Grant scope specifies different protocol than what appears in the configure message.` | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.