Skip to content

Commit d6ad1d6

Browse files
authored
merge release 1.3.0 into main
Merge 1.3.0 to main
2 parents e532f6e + e052b1a commit d6ad1d6

File tree

10 files changed

+260
-127
lines changed

10 files changed

+260
-127
lines changed

.github/workflows/keyfactor-starter-workflow.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Keyfactor Bootstrap Workflow
1+
name: Keyfactor Bootstrap Workflow
22

33
on:
44
workflow_dispatch:
@@ -11,10 +11,17 @@ on:
1111

1212
jobs:
1313
call-starter-workflow:
14-
uses: keyfactor/actions/.github/workflows/[email protected]
14+
uses: keyfactor/actions/.github/workflows/starter.yml@v4
15+
with:
16+
command_token_url: ${{ vars.COMMAND_TOKEN_URL }}
17+
command_hostname: ${{ vars.COMMAND_HOSTNAME }}
18+
command_base_api_path: ${{ vars.COMMAND_API_PATH }}
1519
secrets:
1620
token: ${{ secrets.V2BUILDTOKEN}}
17-
APPROVE_README_PUSH: ${{ secrets.APPROVE_README_PUSH}}
1821
gpg_key: ${{ secrets.KF_GPG_PRIVATE_KEY }}
1922
gpg_pass: ${{ secrets.KF_GPG_PASSPHRASE }}
2023
scan_token: ${{ secrets.SAST_TOKEN }}
24+
entra_username: ${{ secrets.DOCTOOL_ENTRA_USERNAME }}
25+
entra_password: ${{ secrets.DOCTOOL_ENTRA_PASSWD }}
26+
command_client_id: ${{ secrets.COMMAND_CLIENT_ID }}
27+
command_client_secret: ${{ secrets.COMMAND_CLIENT_SECRET }}

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
v1.3.0
2+
- Add support for renewing certificate bound to the HTTPS server
3+
14
v1.2.0
25
- Allow for the management (renew/replace) of bound certificates
36

Fortigate/Api/HttpsUsage.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//Copyright 2023 Keyfactor
2+
//Licensed under the Apache License, Version 2.0 (the "License");
3+
//you may not use this file except in compliance with the License.
4+
//You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
//Unless required by applicable law or agreed to in writing, software
9+
//distributed under the License is distributed on an "AS IS" BASIS,
10+
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
//See the License for the specific language governing permissions and
12+
//limitations under the License.
13+
14+
using Newtonsoft.Json;
15+
using System.Text.Json.Serialization;
16+
17+
namespace Keyfactor.Extensions.Orchestrator.Fortigate.Api
18+
{
19+
public class HttpsUsage
20+
{
21+
[JsonProperty("admin-server-cert")]
22+
public string AdminServerCert { get; set; }
23+
}
24+
25+
public class HttpUsageRequest
26+
{
27+
[JsonProperty("admin-server-cert")]
28+
public OriginKey AdminServerCert { get; set; }
29+
}
30+
31+
public class OriginKey
32+
{
33+
[JsonProperty("q_origin_key")]
34+
public string QOriginKey { get; set; }
35+
}
36+
}

Fortigate/Fortigate.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<AppendTargetFrameworkToOutputPath>true</AppendTargetFrameworkToOutputPath>
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="BouncyCastle.Cryptography" Version="2.0.0" />
11+
<PackageReference Include="BouncyCastle.Cryptography" Version="2.6.2" />
1212
<PackageReference Include="Keyfactor.Logging" Version="1.1.1" />
1313
<PackageReference Include="Keyfactor.Orchestrators.IOrchestratorJobExtensions" Version="0.7.0" />
1414

Fortigate/FortigateStore.cs

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
using System.Text;
3030
using System.Net.Http.Headers;
3131
using Microsoft.Extensions.Logging;
32+
using Org.BouncyCastle.Asn1.Ocsp;
3233

3334
namespace Keyfactor.Extensions.Orchestrator.Fortigate
3435
{
@@ -53,6 +54,7 @@ public class FortigateStore
5354
private static readonly string delete_certificate_api = "/api/v2/cmdb/vpn.certificate/local/";
5455

5556
private static readonly string cert_usage_api = "/api/v2/monitor/system/object/usage";
57+
private static readonly string https_usage_api = "/api/v2/cmdb/system/global";
5658

5759
private readonly HttpClientHandler handler = new HttpClientHandler()
5860
{
@@ -149,6 +151,46 @@ public Usage Usage(string alias, int qtype)
149151
}
150152
}
151153

154+
public string HttpsServerUsage()
155+
{
156+
logger.MethodEntry(LogLevel.Debug);
157+
158+
try
159+
{
160+
var result = GetResource(https_usage_api, new Dictionary<String, String>());
161+
return JsonConvert.DeserializeObject<FortigateResponse<HttpsUsage>>(result).results.AdminServerCert;
162+
}
163+
catch (Exception ex)
164+
{
165+
logger.LogError(FortigateException.FlattenExceptionMessages(ex, $"Error checking https bindings: "));
166+
throw;
167+
}
168+
finally
169+
{
170+
logger.MethodExit(LogLevel.Debug);
171+
}
172+
}
173+
174+
public void UpdateHttpsServerUsage(string alias)
175+
{
176+
logger.MethodEntry(LogLevel.Debug);
177+
HttpUsageRequest request = new HttpUsageRequest() { AdminServerCert = new OriginKey() { QOriginKey = alias } };
178+
179+
try
180+
{
181+
PutAsJson(https_usage_api, request, new Dictionary<string, string>());
182+
}
183+
catch (Exception ex)
184+
{
185+
logger.LogError(FortigateException.FlattenExceptionMessages(ex, $"Error updating https server binding: "));
186+
throw;
187+
}
188+
finally
189+
{
190+
logger.MethodExit(LogLevel.Debug);
191+
}
192+
}
193+
152194
public void Insert(string alias, string cert, string privateKey, bool overwrite, string password = null)
153195
{
154196
logger.MethodEntry(LogLevel.Debug);
@@ -170,9 +212,10 @@ public void Insert(string alias, string cert, string privateKey, bool overwrite,
170212

171213
//check to see if it's in use
172214
existingUsage = Usage(alias, certItem.q_type);
215+
bool existingHttpsUsage = HttpsServerUsage() == alias;
173216

174217
//if it's currently in use
175-
if (existingUsage != null && existingUsage.currently_using != null && existingUsage.currently_using.Length > 0)
218+
if ((existingUsage != null && existingUsage.currently_using != null && existingUsage.currently_using.Length > 0) || existingHttpsUsage)
176219
{
177220
//if newAlias exists, end with error
178221
if (byNewAlias.Length > 0)
@@ -184,10 +227,18 @@ public void Insert(string alias, string cert, string privateKey, bool overwrite,
184227
logger.LogDebug("Inserting alias:" + newAlias);
185228
Insert(newAlias, cert, privateKey, password);
186229

187-
foreach (var existingUsing in existingUsage.currently_using)
230+
if (existingUsage != null && existingUsage.currently_using != null && existingUsage.currently_using.Length > 0)
231+
{
232+
foreach (var existingUsing in existingUsage.currently_using)
233+
{
234+
logger.LogDebug($"Update binding for path/name/attribute {existingUsing.path}/{existingUsing.name}/{existingUsing.attribute} for new alias {newAlias}");
235+
UpdateUsage(newAlias, existingUsing.path, existingUsing.name, existingUsing.attribute);
236+
}
237+
}
238+
239+
if (existingHttpsUsage)
188240
{
189-
logger.LogDebug($"Update binding for path/name/attribute {existingUsing.path}/{existingUsing.name}/{existingUsing.attribute} for new alias {newAlias}");
190-
UpdateUsage(newAlias, existingUsing.path, existingUsing.name, existingUsing.attribute);
241+
UpdateHttpsServerUsage(newAlias);
191242
}
192243

193244
logger.LogDebug("Deleting alias:" + alias);

0 commit comments

Comments
 (0)