SUMMARY = "Installs CoreOS certificates and keys"
DESCRIPTION = "Installs CoreOS certificates and keys that are used during the build"
AUTHOR = "Patrick Vogelaar"
LICENSE = "CLOSED"

SRC_URI = "git://git@bitbucket.gad.local:7999/ico/development-keys.git;protocol=ssh;branch=master"
SRCREV = "2b5d6941ea8759db90f07e195bb1855f618cccb7"

S = "${WORKDIR}/git"

inherit deploy native

CERTIFICATES_AND_KEYS_DIR ?= "${datadir}/keys/"

#FILES:${PN} += "${CERTIFICATES_AND_KEYS_DIR}/*"


do_install() {
    install -d "${D}/${CERTIFICATES_AND_KEYS_DIR}"
    install -m 755 ${S}/db.auth ${D}/${CERTIFICATES_AND_KEYS_DIR}/db.auth
    install -m 755 ${S}/db.crt ${D}/${CERTIFICATES_AND_KEYS_DIR}/db.crt
    install -m 755 ${S}/db.der ${D}/${CERTIFICATES_AND_KEYS_DIR}/db.der
    install -m 755 ${S}/db.esl ${D}/${CERTIFICATES_AND_KEYS_DIR}/db.esl
    install -m 755 ${S}/db.key ${D}/${CERTIFICATES_AND_KEYS_DIR}/db.key
    install -m 755 ${S}/KEK.auth ${D}/${CERTIFICATES_AND_KEYS_DIR}/KEK.auth
    install -m 755 ${S}/KEK.crt ${D}/${CERTIFICATES_AND_KEYS_DIR}/KEK.crt
    install -m 755 ${S}/KEK.der ${D}/${CERTIFICATES_AND_KEYS_DIR}/KEK.der
    install -m 755 ${S}/KEK.esl ${D}/${CERTIFICATES_AND_KEYS_DIR}/KEK.esl
    install -m 755 ${S}/KEK.key ${D}/${CERTIFICATES_AND_KEYS_DIR}/KEK.key
    install -m 755 ${S}/PK.auth ${D}/${CERTIFICATES_AND_KEYS_DIR}/PK.auth
    install -m 755 ${S}/PK.crt ${D}/${CERTIFICATES_AND_KEYS_DIR}/PK.crt
    install -m 755 ${S}/PK.der ${D}/${CERTIFICATES_AND_KEYS_DIR}/PK.der
    install -m 755 ${S}/PK.esl ${D}/${CERTIFICATES_AND_KEYS_DIR}/PK.esl
    install -m 755 ${S}/PK.key ${D}/${CERTIFICATES_AND_KEYS_DIR}/PK.key
    install -m 755 ${S}/swupdate.crt ${D}/${CERTIFICATES_AND_KEYS_DIR}/swupdate.crt
    install -m 755 ${S}/swupdate.key ${D}/${CERTIFICATES_AND_KEYS_DIR}/swupdate.key

    bbwarn "Development certificates and keys are added into the image (UNSECURE)! This image must not be released!"
}


# Public key needed by firmware very depending on the implementation
# So we copy all type of public key (*.auth, *.esl, *.crt, *der)

addtask deploy after do_compile
do_deploy() {
    install -D -m 644 ${S}/KEK.auth ${DEPLOYDIR}/KEK.auth
    install -D -m 644 ${S}/db.auth ${DEPLOYDIR}/db.auth
    install -D -m 644 ${S}/PK.auth ${DEPLOYDIR}/PK.auth

    install -D -m 644 ${S}/KEK.esl ${DEPLOYDIR}/KEK.esl
    install -D -m 644 ${S}/db.esl ${DEPLOYDIR}/db.esl
    install -D -m 644 ${S}/PK.esl ${DEPLOYDIR}/PK.esl

    install -D -m 644 ${S}/KEK.crt ${DEPLOYDIR}/KEK.crt
    install -D -m 644 ${S}/db.crt ${DEPLOYDIR}/db.crt
    install -D -m 644 ${S}/PK.crt ${DEPLOYDIR}/PK.crt

    install -D -m 644 ${S}/KEK.der ${DEPLOYDIR}/KEK.der
    install -D -m 644 ${S}/db.der ${DEPLOYDIR}/db.der
    install -D -m 644 ${S}/PK.der ${DEPLOYDIR}/PK.der

    # !SECURITY WARNING!
    # .key file are not copied to DEPLOYDIR, as they contains the PRIVATE keys
}