Skip to content

Commit 85567dc

Browse files
authored
[CI] Use an in-repo copy of devcerts installation script (#8548)
1 parent 4f2f71a commit 85567dc

File tree

5 files changed

+111
-16
lines changed

5 files changed

+111
-16
lines changed

eng/pipelines/templates/BuildAndTest.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,7 @@ steps:
6060
- ${{ if and(eq(parameters.runAsPublic, 'true'), eq(parameters.runPipelineTests, 'true')) }}:
6161
# non-helix tests
6262
- ${{ if ne(parameters.isWindows, 'true') }}:
63-
- script: mkdir ${{ parameters.repoArtifactsPath }}/devcert-scripts &&
64-
cd ${{ parameters.repoArtifactsPath }}/devcert-scripts &&
65-
wget https://raw.githubusercontent.com/BorisWilhelms/create-dotnet-devcert/main/scripts/ubuntu-create-dotnet-devcert.sh &&
66-
wget https://raw.githubusercontent.com/BorisWilhelms/create-dotnet-devcert/main/scripts/common.sh &&
67-
chmod +x ubuntu-create-dotnet-devcert.sh &&
68-
./ubuntu-create-dotnet-devcert.sh
63+
- script: $(Build.SourcesDirectory)/tests/external-scripts/ubuntu-create-dotnet-devcert.sh
6964
displayName: Install devcerts
7065

7166
- ${{ if eq(parameters.isWindows, 'true') }}:

tests/external-scripts/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# external-scripts
2+
3+
This is a copy of scripts from https://github.com/BorisWilhelms/create-dotnet-devcert/ . This is being used for now as `dotnet dev-certs https --trust` doesn't seem to be working on our CI.

tests/external-scripts/common.sh

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/bin/sh
2+
SAVE=0
3+
4+
usage() {
5+
echo "Usage: $0 [-s]"
6+
echo "Generates a valid ASP.NET Core self-signed certificate for the local machine."
7+
echo "The certificate will be imported into the system's certificate store and into various other places."
8+
echo " -s: Also saves the generated crtfile to the home directory"
9+
exit 1
10+
}
11+
12+
while getopts "sh" opt
13+
do
14+
case "$opt" in
15+
s)
16+
SAVE=1
17+
;;
18+
h)
19+
usage
20+
exit 1
21+
;;
22+
*)
23+
;;
24+
esac
25+
done
26+
27+
TMP_PATH=/var/tmp/localhost-dev-cert
28+
if [ ! -d $TMP_PATH ]; then
29+
mkdir $TMP_PATH
30+
fi
31+
32+
cleanup() {
33+
rm -R $TMP_PATH
34+
}
35+
36+
KEYFILE=$TMP_PATH/dotnet-devcert.key
37+
CRTFILE=$TMP_PATH/dotnet-devcert.crt
38+
PFXFILE=$TMP_PATH/dotnet-devcert.pfx
39+
40+
NSSDB_PATHS="$HOME/.pki/nssdb \
41+
$HOME/snap/chromium/current/.pki/nssdb \
42+
$HOME/snap/postman/current/.pki/nssdb"
43+
44+
CONF_PATH=$TMP_PATH/localhost.conf
45+
cat >> $CONF_PATH <<EOF
46+
[req]
47+
prompt = no
48+
default_bits = 2048
49+
distinguished_name = subject
50+
req_extensions = req_ext
51+
x509_extensions = x509_ext
52+
53+
[ subject ]
54+
commonName = localhost
55+
56+
[req_ext]
57+
basicConstraints = critical, CA:true
58+
subjectAltName = @alt_names
59+
60+
[x509_ext]
61+
basicConstraints = critical, CA:true
62+
keyUsage = critical, keyCertSign, cRLSign, digitalSignature,keyEncipherment
63+
extendedKeyUsage = critical, serverAuth
64+
subjectAltName = critical, @alt_names
65+
1.3.6.1.4.1.311.84.1.1 = ASN1:UTF8String:ASP.NET Core HTTPS development certificate # Needed to get it imported by dotnet dev-certs
66+
67+
[alt_names]
68+
DNS.1 = localhost
69+
EOF
70+
71+
configure_nssdb() {
72+
echo "Configuring nssdb for $1"
73+
certutil -d sql:"$1" -D -n dotnet-devcert
74+
certutil -d sql:"$1" -A -t "CP,," -n dotnet-devcert -i $CRTFILE
75+
}
76+
77+
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout $KEYFILE -out $CRTFILE -config $CONF_PATH --passout pass:
78+
openssl pkcs12 -export -out $PFXFILE -inkey $KEYFILE -in $CRTFILE --passout pass:
79+
80+
for NSSDB in $NSSDB_PATHS; do
81+
if [ -d "$NSSDB" ]; then
82+
configure_nssdb "$NSSDB"
83+
fi
84+
done
85+
86+
if [ "$(id -u)" -ne 0 ]; then
87+
# shellcheck disable=SC2034 # SUDO will be used in parent scripts.
88+
SUDO='sudo'
89+
fi
90+
91+
dotnet dev-certs https --clean --import $PFXFILE -p ""
92+
93+
if [ "$SAVE" = 1 ]; then
94+
cp $CRTFILE $HOME
95+
echo "Saved certificate to $HOME/$(basename $CRTFILE)"
96+
cp $PFXFILE $HOME
97+
echo "Saved certificate to $HOME/$(basename $PFXFILE)"
98+
fi
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/common.sh"
3+
4+
$SUDO rm /etc/ssl/certs/dotnet-devcert.pem
5+
$SUDO cp $CRTFILE "/usr/local/share/ca-certificates"
6+
$SUDO update-ca-certificates
7+
8+
cleanup

tests/helix/send-to-helix-inner.proj

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,10 @@
1919
<_DotNetToolJsonPath>$(RepoRoot).config/dotnet-tools.json</_DotNetToolJsonPath>
2020
<_DotNetToolJsonContent>$([System.IO.File]::ReadAllText($(_DotNetToolJsonPath)))</_DotNetToolJsonContent>
2121

22-
<_CreateDotNetDevCertsDirectory>$(ArtifactsObjDir)create-dotnet-devcert</_CreateDotNetDevCertsDirectory>
23-
2422
<_AzureFunctionsCliUrl Condition="'$(OS)' == 'Windows_NT'">https://github.com/Azure/azure-functions-core-tools/releases/download/4.0.6280/Azure.Functions.Cli.min.win-x64_net8.4.0.6280.zip</_AzureFunctionsCliUrl>
2523
<_AzureFunctionsCliUrl Condition="'$(OS)' != 'Windows_NT'">https://github.com/Azure/azure-functions-core-tools/releases/download/4.0.6280/Azure.Functions.Cli.linux-x64_net8.4.0.6280.zip</_AzureFunctionsCliUrl>
2624

2725
<_DefaultSdkDirNameForTests>dotnet-tests</_DefaultSdkDirNameForTests>
28-
29-
<PrepareDependenciesDependsOn>_StageCreateDotNetDevCertScripts</PrepareDependenciesDependsOn>
3026
</PropertyGroup>
3127

3228
<PropertyGroup>
@@ -164,11 +160,6 @@
164160

165161
<Target Name="PrepareDependencies" DependsOnTargets="$(PrepareDependenciesDependsOn)" />
166162

167-
<Target Name="_StageCreateDotNetDevCertScripts" Condition="'$(NeedsCreateDotNetDevScripts)' == 'true' and '$(OS)' != 'Windows_NT' and !Exists($(_CreateDotNetDevCertsDirectory))">
168-
<DownloadFile SourceUrl="https://raw.githubusercontent.com/BorisWilhelms/create-dotnet-devcert/main/scripts/ubuntu-create-dotnet-devcert.sh" DestinationFolder="$(_CreateDotNetDevCertsDirectory)" />
169-
<DownloadFile SourceUrl="https://raw.githubusercontent.com/BorisWilhelms/create-dotnet-devcert/main/scripts/common.sh" DestinationFolder="$(_CreateDotNetDevCertsDirectory)" />
170-
</Target>
171-
172163
<Target Name="BuildHelixWorkItems" DependsOnTargets="$(BuildHelixWorkItemsDependsOn)" BeforeTargets="Build">
173164
<MSBuild Projects="$(RepoRoot)\eng\dcppack\Aspire.Hosting.Orchestration.$(NETCoreSdkRuntimeIdentifier).csproj" Targets="GetDCPBinaryLocation">
174165
<Output TaskParameter="TargetOutputs" PropertyName="DCPBinaryLocation" />
@@ -187,7 +178,7 @@
187178
</PropertyGroup>
188179

189180
<ItemGroup Label="Common payload">
190-
<HelixCorrelationPayload Condition="'$(NeedsCreateDotNetDevScripts)' == 'true'" Include="$(_CreateDotNetDevCertsDirectory)" Destination="create-dotnet-devcert" />
181+
<HelixCorrelationPayload Condition="'$(NeedsCreateDotNetDevScripts)' == 'true'" Include="$(RepoRoot)tests\external-scripts" Destination="create-dotnet-devcert" />
191182
<HelixCorrelationPayload Condition="'$(DockerCliToolDir)' != ''" Include="$(DockerCliToolDir)" Destination="docker-cli" />
192183
</ItemGroup>
193184

0 commit comments

Comments
 (0)