@@ -31,6 +31,7 @@ func NewDefaultDomainIndexer(dnsResolver DNSResolver, domainStore DomainStore, d
3131 domainRenewalInterval : domainRenewalInterval ,
3232 dnsResolver : dnsResolver ,
3333 domainStore : domainStore ,
34+ currentPrivateKey : make (map [string ]keyAlias ),
3435 }
3536
3637 myPrivateKeys , err := privateKeysToKeyMap (base64PrivateKeys )
@@ -39,12 +40,14 @@ func NewDefaultDomainIndexer(dnsResolver DNSResolver, domainStore DomainStore, d
3940 }
4041 di .myPrivateKeys = myPrivateKeys
4142
42- for _ , privateKey := range di .myPrivateKeys {
43- // since iterating over a map is non-deterministic, we can make sure to set the key
44- // either if it is not already set or it is alphabetically less than current key at the index when
45- // iterating over the private keys map.
46- if di .currentPrivateKey == "" || di .currentPrivateKey < privateKey .alias {
47- di .currentPrivateKey = privateKey .alias
43+ for originCallsign := range di .myPrivateKeys {
44+ for _ , privateKey := range di .myPrivateKeys [originCallsign ] {
45+ // since iterating over a map is non-deterministic, we can make sure to set the key
46+ // either if it is not already set or it is alphabetically less than current key at the index when
47+ // iterating over the private keys map.
48+ if di .currentPrivateKey [originCallsign ] == "" || di .currentPrivateKey [originCallsign ] < privateKey .alias {
49+ di .currentPrivateKey [originCallsign ] = privateKey .alias
50+ }
4851 }
4952 }
5053
@@ -62,8 +65,8 @@ type defaultDomainIndexer struct {
6265 lastRun time.Time
6366 lastRunLock sync.RWMutex
6467
65- myPrivateKeys keyMap
66- currentPrivateKey keyAlias
68+ myPrivateKeys map [ string ] keyMap
69+ currentPrivateKey map [ string ] keyAlias
6770
6871 dnsResolver DNSResolver
6972 domainStore DomainStore
@@ -227,21 +230,27 @@ func (di *defaultDomainIndexer) checkDomainForKeyRecords(ctx context.Context, cu
227230 }
228231
229232 // create shared secrets for each private key + public key combination
230- for _ , myKey := range di .myPrivateKeys {
231- for _ , theirKey := range currentDomainInfo .allPublicKeys {
232- keyPairAlias := newKeyPairAlias (myKey .alias , theirKey .alias )
233- if currentDomainInfo .allSharedSecrets [keyPairAlias ] == nil {
234- currentDomainInfo .allSharedSecrets [keyPairAlias ], err = calculateSharedSecret (myKey , theirKey )
235- if err != nil {
236- logger .Warningf ("error calculating shared secret for record %s: %v" , currentDomainInfo .Domain , err )
237- currentDomainInfo .domainStatus = DomainStatusErrorOnSharedSecretCalculation
233+ for originCallsign := range di .myPrivateKeys {
234+ if originCallsign != currentDomainInfo .Domain {
235+ continue
236+ }
237+
238+ for _ , myKey := range di .myPrivateKeys [originCallsign ] {
239+ for _ , theirKey := range currentDomainInfo .allPublicKeys {
240+ keyPairAlias := newKeyPairAlias (myKey .alias , theirKey .alias )
241+ if currentDomainInfo .allSharedSecrets [keyPairAlias ] == nil {
242+ currentDomainInfo .allSharedSecrets [keyPairAlias ], err = calculateSharedSecret (myKey , theirKey )
243+ if err != nil {
244+ logger .Warningf ("error calculating shared secret for record %s: %v" , currentDomainInfo .Domain , err )
245+ currentDomainInfo .domainStatus = DomainStatusErrorOnSharedSecretCalculation
246+ }
238247 }
239248 }
240249 }
241- }
242250
243- currentDomainInfo .currentSharedSecretId = newKeyPairAlias (di .currentPrivateKey , currentDomainInfo .currentPublicKeyId )
244- currentDomainInfo .lastUpdateTime = time .Now ()
251+ currentDomainInfo .currentSharedSecretId = newKeyPairAlias (di .currentPrivateKey [originCallsign ], currentDomainInfo .currentPublicKeyId )
252+ currentDomainInfo .lastUpdateTime = time .Now ()
253+ }
245254}
246255
247256func parsePolicyRecords (baseSubdomain string , baseSubdomainRecords []string ) (foundDomains []string , parseError bool ) {
0 commit comments