-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
39236d9
commit 0da524b
Showing
16 changed files
with
274 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,3 @@ export * from './signing-provider' | |
|
||
export * from './webcrypto' | ||
export * from './hashes' | ||
export * from './x509' |
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 was deleted.
Oops, something went wrong.
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,52 @@ | ||
import { AgentContext } from '../../agent' | ||
import { injectable } from '../../plugins' | ||
|
||
import { X509ModuleConfig } from './X509ModuleConfig' | ||
import { X509Service } from './X509Service' | ||
import { X509CreateSelfSignedCertificateOptions, X509ValidateCertificateChainOptions } from './X509ServiceOptions' | ||
|
||
/** | ||
* @public | ||
*/ | ||
@injectable() | ||
export class X509Api { | ||
public constructor(private agentContext: AgentContext, private x509Service: X509Service) {} | ||
|
||
/** | ||
* Adds a trusted certificate to the X509 Module Config. | ||
* | ||
* @param certificate | ||
*/ | ||
public async addTrustedCertificate(certificate: string) { | ||
const x509ModuleConfig = this.agentContext.dependencyManager.resolve(X509ModuleConfig) | ||
x509ModuleConfig.addTrustedCertificate(certificate) | ||
} | ||
|
||
/** | ||
* Overwrites the trusted certificates in the X509 Module Config. | ||
* | ||
* @param certificate | ||
*/ | ||
public async setTrustedCertificates(certificates?: [string, ...string[]]) { | ||
const x509ModuleConfig = this.agentContext.dependencyManager.resolve(X509ModuleConfig) | ||
x509ModuleConfig.setTrustedCertificates(certificates) | ||
} | ||
|
||
/** | ||
* Creates a self-signed certificate. | ||
* | ||
* @param options X509CreateSelfSignedCertificateOptions | ||
*/ | ||
public async createSelfSignedCertificate(options: X509CreateSelfSignedCertificateOptions) { | ||
return await X509Service.createSelfSignedCertificate(this.agentContext, options) | ||
} | ||
|
||
/** | ||
* Validate a certificate chain. | ||
* | ||
* @param options X509ValidateCertificateChainOptions | ||
*/ | ||
public async validateCertificateChain(options: X509ValidateCertificateChainOptions) { | ||
return await X509Service.validateCertificateChain(this.agentContext, options) | ||
} | ||
} |
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
File renamed without changes.
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,39 @@ | ||
import type { X509ModuleConfigOptions } from './X509ModuleConfig' | ||
import type { Module, DependencyManager } from '../../plugins' | ||
|
||
import { AgentConfig } from '../../agent/AgentConfig' | ||
|
||
import { X509Api } from './X509Api' | ||
import { X509ModuleConfig } from './X509ModuleConfig' | ||
import { X509Service } from './X509Service' | ||
|
||
/** | ||
* @public | ||
*/ | ||
export class X509Module implements Module { | ||
public readonly api = X509Api | ||
|
||
public readonly config: X509ModuleConfig | ||
|
||
public constructor(options: X509ModuleConfigOptions) { | ||
this.config = new X509ModuleConfig(options) | ||
} | ||
|
||
/** | ||
* Registers the dependencies of the sd-jwt-vc module on the dependency manager. | ||
*/ | ||
public register(dependencyManager: DependencyManager) { | ||
// Warn about experimental module | ||
dependencyManager | ||
.resolve(AgentConfig) | ||
.logger.warn( | ||
"The 'X509' module is experimental and could have unexpected breaking changes. When using this module, make sure to use strict versions for all @credo-ts packages." | ||
) | ||
|
||
// Register config | ||
dependencyManager.registerInstance(X509ModuleConfig, this.config) | ||
|
||
// Services | ||
dependencyManager.registerSingleton(X509Service) | ||
} | ||
} |
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,27 @@ | ||
export interface X509ModuleConfigOptions { | ||
trustedCertificates?: [string, ...string[]] | ||
} | ||
|
||
export class X509ModuleConfig { | ||
private options: X509ModuleConfigOptions | ||
|
||
public constructor(options: X509ModuleConfigOptions) { | ||
this.options = options | ||
} | ||
|
||
public get trustedCertificates() { | ||
return this.options.trustedCertificates | ||
} | ||
|
||
public setTrustedCertificates(trustedCertificates?: [string, ...string[]]) { | ||
this.options.trustedCertificates = trustedCertificates | ||
} | ||
|
||
public addTrustedCertificate(trustedCertificate: string) { | ||
if (!this.options.trustedCertificates) { | ||
this.options.trustedCertificates = [trustedCertificate] | ||
} | ||
|
||
this.options.trustedCertificates.push(trustedCertificate) | ||
} | ||
} |
Oops, something went wrong.