@@ -81,54 +81,64 @@ public override void Synchronize(ICertificateDataReader certificateDataReader,
8181 Logger . MethodEntry ( ILogExtensions . MethodLogLevel . Debug ) ;
8282 try
8383 {
84+ CertificateListResponse certs ;
85+
8486 if ( certificateAuthoritySyncInfo . DoFullSync )
8587 {
86- var certs = Task . Run ( async ( ) => await CscGlobalClient . SubmitCertificateListRequestAsync ( ) ) . Result ;
88+ Logger . Trace ( "Performing Full Sync" ) ;
89+ certs = Task . Run ( async ( ) => await CscGlobalClient . SubmitCertificateListRequestAsync ( ) ) . Result ;
90+ }
91+ else
92+ {
93+ // Incremental sync - get certificates from the last X days (default 5)
94+ var effectiveDate = DateTime . Now . AddDays ( - Constants . IncrementalSyncDays ) ;
95+ Logger . Trace ( $ "Performing Incremental Sync with effectiveDate: { effectiveDate : yyyy/MM/dd} ") ;
96+ certs = Task . Run ( async ( ) => await CscGlobalClient . SubmitIncrementalCertificateListRequestAsync ( effectiveDate ) ) . Result ;
97+ }
98+
99+ foreach ( var currentResponseItem in certs . Results )
100+ {
101+
102+ cancelToken . ThrowIfCancellationRequested ( ) ;
103+ Logger . Trace ( $ "Took Certificate ID { currentResponseItem ? . Uuid } from Queue") ;
104+ var certStatus = _requestManager . MapReturnStatus ( currentResponseItem ? . Status ) ;
87105
88- foreach ( var currentResponseItem in certs . Results )
106+ //Keyfactor sync only seems to work when there is a valid cert and I can only get Active valid certs from Csc Global
107+ if ( certStatus == Convert . ToInt32 ( PKIConstants . Microsoft . RequestDisposition . ISSUED ) ||
108+ certStatus == Convert . ToInt32 ( PKIConstants . Microsoft . RequestDisposition . REVOKED ) )
89109 {
110+ //One click renewal/reissue won't work for this implementation so there is an option to disable it by not syncing back template
111+ var productId = "CscGlobal" ;
112+ if ( EnableTemplateSync ) productId = currentResponseItem ? . CertificateType ;
90113
91- cancelToken . ThrowIfCancellationRequested ( ) ;
92- Logger . Trace ( $ "Took Certificate ID { currentResponseItem ? . Uuid } from Queue" ) ;
93- var certStatus = _requestManager . MapReturnStatus ( currentResponseItem ? . Status ) ;
114+ var fileContent =
115+ Encoding . ASCII . GetString (
116+ Convert . FromBase64String ( currentResponseItem ? . Certificate ?? string . Empty ) ) ;
94117
95- //Keyfactor sync only seems to work when there is a valid cert and I can only get Active valid certs from Csc Global
96- if ( certStatus == Convert . ToInt32 ( PKIConstants . Microsoft . RequestDisposition . ISSUED ) ||
97- certStatus == Convert . ToInt32 ( PKIConstants . Microsoft . RequestDisposition . REVOKED ) )
118+ if ( fileContent . Length > 0 )
98119 {
99- //One click renewal/reissue won't work for this implementation so there is an option to disable it by not syncing back template
100- var productId = "CscGlobal" ;
101- if ( EnableTemplateSync ) productId = currentResponseItem ? . CertificateType ;
102-
103- var fileContent =
104- Encoding . ASCII . GetString (
105- Convert . FromBase64String ( currentResponseItem ? . Certificate ?? string . Empty ) ) ;
120+ Logger . Trace ( $ "File Content { fileContent } ") ;
121+ var certData = fileContent . Replace ( "\r \n " , string . Empty ) ;
122+ var certString = GetEndEntityCertificate ( certData ) ;
123+ var currentCert = new X509Certificate2 ( Encoding . ASCII . GetBytes ( certString ) ) ;
106124
107- if ( fileContent . Length > 0 )
125+ if ( certString . Length > 0 )
108126 {
109- Logger . Trace ( $ "File Content { fileContent } ") ;
110- var certData = fileContent . Replace ( "\r \n " , string . Empty ) ;
111- var certString = GetEndEntityCertificate ( certData ) ;
112- var currentCert = new X509Certificate2 ( Encoding . ASCII . GetBytes ( certString ) ) ;
113-
114- if ( certString . Length > 0 )
127+ blockingBuffer . Add ( new CAConnectorCertificate
115128 {
116- blockingBuffer . Add ( new CAConnectorCertificate
117- {
118- CARequestID = $ "{ currentResponseItem ? . Uuid } ",
119- Certificate = certString ,
120- SubmissionDate = currentResponseItem ? . OrderDate == null
121- ? Convert . ToDateTime ( currentCert . NotBefore )
122- : Convert . ToDateTime ( currentResponseItem . OrderDate ) ,
123- Status = certStatus ,
124- ProductID = productId
125- } , cancelToken ) ;
126- }
129+ CARequestID = $ "{ currentResponseItem ? . Uuid } ",
130+ Certificate = certString ,
131+ SubmissionDate = currentResponseItem ? . OrderDate == null
132+ ? Convert . ToDateTime ( currentCert . NotBefore )
133+ : Convert . ToDateTime ( currentResponseItem . OrderDate ) ,
134+ Status = certStatus ,
135+ ProductID = productId
136+ } , cancelToken ) ;
127137 }
128138 }
129139 }
130- blockingBuffer . CompleteAdding ( ) ;
131140 }
141+ blockingBuffer . CompleteAdding ( ) ;
132142 }
133143 catch ( Exception e )
134144 {
0 commit comments