@@ -397,6 +397,19 @@ function credentialRefOf(auth: ConnectorInstanceAuth | undefined): string | unde
397397 return auth . credentialRef ;
398398}
399399
400+ /**
401+ * ADR-0143 D2.3 — the vendor public-key reference a `signed` instance names
402+ * beside its key, for a scheme whose vendor signs its responses (`alipay-v3`).
403+ */
404+ function vendorPublicKeyRefOf ( auth : ConnectorInstanceAuth | undefined ) : string | undefined {
405+ return auth ?. type === 'signed' && auth . scheme === 'alipay-v3' ? auth . vendorPublicKeyRef : undefined ;
406+ }
407+
408+ /** [#27237] Every reference an instance's `auth` names: its `credentialRef`, and a vendor public key's. */
409+ function credentialRefsOf ( auth : ConnectorInstanceAuth | undefined ) : string [ ] {
410+ return [ credentialRefOf ( auth ) , vendorPublicKeyRefOf ( auth ) ] . filter ( ( ref ) : ref is string => ref !== undefined ) ;
411+ }
412+
400413/** The `basic` username an instance sends beside its secret — what its `Authorization` header encodes with it. */
401414function basicUsernameOf ( auth : ConnectorInstanceAuth | undefined ) : string | undefined {
402415 return auth ?. type === 'basic' ? auth . username : undefined ;
@@ -2211,7 +2224,7 @@ export class AutomationServicePlugin implements Plugin {
22112224 // read is not one that is absent, so the rows count as unreadable then.
22122225 let chain : ConnectorCredentialChain = { vault : this . options . credentialResolver } ;
22132226 let credentialRows : Map < string , ConnectorCredentialRecord > | undefined = new Map ( ) ;
2214- if ( [ ...desired . values ( ) ] . some ( ( d ) => credentialRefOf ( d . entry . auth ) !== undefined ) ) {
2227+ if ( [ ...desired . values ( ) ] . some ( ( d ) => credentialRefsOf ( d . entry . auth ) . length > 0 ) ) {
22152228 try {
22162229 chain = await this . connectorCredentialChain ( ctx ) ;
22172230 if ( chain . store ) credentialRows = await chain . store . list ( ) ;
@@ -2227,11 +2240,11 @@ export class AutomationServicePlugin implements Plugin {
22272240 }
22282241 const credentialSources = new Map < string , string > ( ) ;
22292242 for ( const d of desired . values ( ) ) {
2230- const ref = credentialRefOf ( d . entry . auth ) ;
2231- if ( ref === undefined ) continue ;
2232- const fingerprint = connectorCredentialFingerprint ( chain , ref , credentialRows ) ;
2233- credentialSources . set ( ref , fingerprint ) ;
2234- d . signature += `|credential: ${ fingerprint } ` ;
2243+ for ( const ref of credentialRefsOf ( d . entry . auth ) ) {
2244+ const fingerprint = connectorCredentialFingerprint ( chain , ref , credentialRows ) ;
2245+ credentialSources . set ( ref , fingerprint ) ;
2246+ d . signature += `|credential: ${ fingerprint } ` ;
2247+ }
22352248 }
22362249 // A refusal of a value the door does not hold stands until an upstream
22372250 // accepts the reference — or the reference stops resolving from the
@@ -2355,20 +2368,48 @@ export class AutomationServicePlugin implements Plugin {
23552368 }
23562369 credential = resolution ;
23572370 }
2371+ // ADR-0143 D2.3 — a scheme that verifies responses names the
2372+ // vendor's public key beside the signing key; it resolves through
2373+ // the same chain and degrades the instance the same way, so a
2374+ // response is never accepted unverified for want of it.
2375+ const vendorRef = vendorPublicKeyRefOf ( entry . auth ) ;
2376+ let vendorPublicKey : string | undefined ;
2377+ if ( vendorRef !== undefined ) {
2378+ let resolution : ConnectorCredentialResolution ;
2379+ try {
2380+ resolution = await resolveConnectorCredential ( chain , vendorRef , credentialRows ) ;
2381+ } catch ( err ) {
2382+ fail (
2383+ `[Automation] connector instance '${ name } ' (provider '${ provider } '): auth resolution failed (ADR-0097 §3).` ,
2384+ err ,
2385+ ) ;
2386+ continue ;
2387+ }
2388+ if ( resolution . kind !== 'resolved' ) {
2389+ await this . degradeConnectorForCredential ( engine , ctx , {
2390+ name, entry, provider, signature, existing, ref : vendorRef , resolution,
2391+ } ) ;
2392+ continue ;
2393+ }
2394+ vendorPublicKey = resolution . value ;
2395+ }
23582396 // ADR-0143 D2.3, D4 — a `signed` instance's key is bound to the
23592397 // signer its scheme names, here, and the provider receives only
23602398 // the signer: the key never crosses into a provider package. A key
2361- // that cannot sign at all is a configuration fault, like an
2362- // unparseable retry policy below.
2399+ // that cannot sign (or a vendor key that cannot verify) is a
2400+ // configuration fault, like an unparseable retry policy below.
23632401 let auth : ResolvedConnectorAuth | undefined ;
23642402 let requestSigner : ConnectorRequestSigner | undefined ;
23652403 if ( entry . auth ?. type === 'signed' ) {
23662404 try {
2367- requestSigner = createConnectorRequestSigner ( name , entry . auth , credential ?. value ?? '' ) ;
2405+ requestSigner = createConnectorRequestSigner ( name , entry . auth , {
2406+ key : credential ?. value ?? '' ,
2407+ ...( vendorPublicKey === undefined ? { } : { vendorPublicKey } ) ,
2408+ } ) ;
23682409 } catch ( err ) {
23692410 fail (
2370- `[Automation] connector instance '${ name } ' (provider '${ provider } '): its signing key cannot sign ` +
2371- `(ADR-0143 D2.3).` ,
2411+ `[Automation] connector instance '${ name } ' (provider '${ provider } '): a key it names cannot sign or ` +
2412+ `verify (ADR-0143 D2.3).` ,
23722413 err ,
23732414 ) ;
23742415 continue ;
@@ -2873,12 +2914,12 @@ export class AutomationServicePlugin implements Plugin {
28732914 const entry = raw as DeclaredConnectorItem & { _packageId ?: unknown } ;
28742915 if ( typeof entry ?. name !== 'string' || entry . name . length === 0 ) continue ;
28752916 if ( typeof entry . provider !== 'string' || entry . provider . length === 0 ) continue ;
2876- const ref = credentialRefOf ( entry . auth ) ;
2877- if ( ref === undefined ) continue ;
28782917 const packageId = typeof entry . _packageId === 'string' && entry . _packageId . length > 0 ? entry . _packageId : undefined ;
2879- const list = out . get ( ref ) ?? [ ] ;
2880- if ( ! list . some ( ( c ) => c . name === entry . name ) ) list . push ( { name : entry . name , ...( packageId ? { packageId } : { } ) } ) ;
2881- out . set ( ref , list ) ;
2918+ for ( const ref of credentialRefsOf ( entry . auth ) ) {
2919+ const list = out . get ( ref ) ?? [ ] ;
2920+ if ( ! list . some ( ( c ) => c . name === entry . name ) ) list . push ( { name : entry . name , ...( packageId ? { packageId } : { } ) } ) ;
2921+ out . set ( ref , list ) ;
2922+ }
28822923 }
28832924 return out ;
28842925 }
0 commit comments