# https://nsis.sourceforge.io/Import_Root_Certificate
# 사용 예
# ${AddCertificateToStore} $0 "$VAR_INSTDIR\rootcert.cer"
!define CERT_QUERY_OBJECT_FILE 1
!define CERT_QUERY_CONTENT_FLAG_ALL 16382
!define CERT_QUERY_FORMAT_FLAG_ALL 14
!define CERT_STORE_PROV_SYSTEM 10
!define CERT_STORE_OPEN_EXISTING_FLAG 0x4000
!define CERT_SYSTEM_STORE_LOCAL_MACHINE 0x20000
!define CERT_STORE_ADD_ALWAYS 4
!macro _AddCertificateToStore un
Function ${un}_AddCertificateToStore
Exch $0
Push $1
Push $R0
System::Call "crypt32::CryptQueryObject(i ${CERT_QUERY_OBJECT_FILE}, w r0, \
i ${CERT_QUERY_CONTENT_FLAG_ALL}, i ${CERT_QUERY_FORMAT_FLAG_ALL}, \
i 0, i 0, i 0, i 0, i 0, i 0, *i .r0) i .R0"
${If} $R0 <> 0
System::Call "crypt32::CertOpenStore(i ${CERT_STORE_PROV_SYSTEM}, i 0, i 0, \
i ${CERT_STORE_OPEN_EXISTING_FLAG}|${CERT_SYSTEM_STORE_LOCAL_MACHINE}, \
w 'ROOT') i .r1"
${If} $1 <> 0
System::Call "crypt32::CertAddCertificateContextToStore(i r1, i r0, \
i ${CERT_STORE_ADD_ALWAYS}, i 0) i .R0"
System::Call "crypt32::CertFreeCertificateContext(i r0)"
${If} $R0 == 0
StrCpy $0 "Unable to add certificate to certificate store"
${Else}
StrCpy $0 "success"
${EndIf}
System::Call "crypt32::CertCloseStore(i r1, i 0)"
${Else}
System::Call "crypt32::CertFreeCertificateContext(i r0)"
StrCpy $0 "Unable to open certificate store"
${EndIf}
${Else}
StrCpy $0 "Unable to open certificate file"
${EndIf}
Pop $R0
Pop $1
Exch $0
FunctionEnd
!macroend
!insertmacro _AddCertificateToStore ""
;!insertmacro _AddCertificateToStore "un."
!macro AddCertificateToStore OUTPUT param
Push "${param}"
!ifndef __UNINSTALL__
Call _AddCertificateToStore
!else
Call un._AddCertificateToStore
!endif
Pop "${OUTPUT}"
!macroend
!define AddCertificateToStore "!insertmacro AddCertificateToStore"
댓글
댓글 쓰기