# Copyright (C) 2024 The Android Open Source Project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. BEGIN { inSPKIBlockList = 0 inKnownInterceptionList = 0 currentHash = 0 if (! package) { package = "org.conscrypt" } } # Keep track of which block definition we are in now. /kSPKIBlockList\[\]\[crypto::kSHA256Length\] = {/ { inSPKIBlockList = 1 } /kKnownInterceptionList\[\]\[crypto::kSHA256Length\] = {/ { inKnownInterceptionList = 1 } /};/ { if (inSPKIBlockList) inSPKIBlockList = 0 if (inKnownInterceptionList) inKnownInterceptionList= 0 } # Extract the bytes from the public key hashes. /\{0x/ { currentHash = "" } /0x/ { newLine = $0 gsub(/[ {}]/, "", newLine) gsub(/0x/, "", newLine) currentHash = currentHash newLine } /\},/ { if (inSPKIBlockList) hashes[currentHash] = 1 if (inKnownInterceptionList) hashes[currentHash] = 0 currentHash = 0 } END { # Make sure we are out of the declaration blocks. if (inSPKIBlockList || inKnownInterceptionList) exit 1 # Only keep the hashes that are only in kSPKIBlockList. for (h in hashes) { if (hashes[h]) { blockedHashes[i++] = h } } # Generate the Java class. print "/*" print " * Copyright (C) 2024 The Android Open Source Project" print " *" print " * Licensed under the Apache License, Version 2.0 (the \"License\");" print " * you may not use this file except in compliance with the License." print " * You may obtain a copy of the License at" print " *" print " * http://www.apache.org/licenses/LICENSE-2.0" print " *" print " * Unless required by applicable law or agreed to in writing, software" print " * distributed under the License is distributed on an \"AS IS\" BASIS," print " * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied." print " * See the License for the specific language governing permissions and" print " * limitations under the License." print " */" print "" print "/* This file was generated by generate_blocklist.awk. Do not modify. */" print "" print "package", package ";" print "" print "final class StaticBlocklist {" print " static final byte[][] PUBLIC_KEYS = {" ORS = "" for (h in blockedHashes) { print " {\n " n = split(blockedHashes[h], splitHash, ",") for (i=1; i<=n; i++) { if (splitHash[i] != "") { print "(byte) 0x" splitHash[i] ", " if (i % 8 == 0) { print "\n " } } } print "},\n" } ORS = "\n" print " };" print "}" }