-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathext.js
64 lines (58 loc) · 2.78 KB
/
ext.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* Copyright © 2024 FirstTimeEZ
* https://github.com/FirstTimeEZ
*
* 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.
*/
/**
* Checks if the given certificate text is valid.
* A valid certificate text starts with "-----BEGIN CERTIFICATE-----"
* and ends with "-----END CERTIFICATE-----" (with or without a newline).
*
* @param {string} certificateText - The certificate text to validate.
* @returns {boolean} True if the certificate text is valid, false otherwise.
*/
export function checkCertificateTextValid(certificateText) {
return certificateText.startsWith("-----BEGIN CERTIFICATE-----") && (certificateText.endsWith("-----END CERTIFICATE-----\n") || certificateText.endsWith("-----END CERTIFICATE-----") || certificateText.endsWith("-----END CERTIFICATE----- "));
}
/**
* Checks if the given private key is valid.
* A valid private key starts with "-----BEGIN PRIVATE KEY-----"
* and ends with "-----END PRIVATE KEY-----" (with or without a newline).
*
* @param {string} privateKey - The private key to validate.
* @returns {boolean} True if the private key is valid, false otherwise.
*/
export function checkPrivateKeyValid(privateKey) {
return privateKey.startsWith("-----BEGIN PRIVATE KEY-----") && (privateKey.endsWith("-----END PRIVATE KEY-----") || privateKey.endsWith("-----END PRIVATE KEY-----\n") || privateKey.endsWith("-----END PRIVATE KEY----- "))
}
/**
* Extracts challenges of a specific type from a list of authorizations.
* Each challenge is marked as unanswered and includes its associated domain
* and wildcard status.
*
* @param {Array} list - The list of authorizations containing challenges.
* @param {string} challengeType - The type of challenge to extract.
* @returns {Array} An array of challenges of the specified type.
*/
export function extractChallengeType(list, challengeType) {
const chals = [];
for (let index = 0; index < list.length; index++) {
const auth = list[index];
for (let i1 = 0; i1 < auth.get.challenges.length; i1++) {
const challenge = auth.get.challenges[i1];
challenge.type == challengeType && (challenge.answered = false, challenge.domain = auth.get.identifier.value, challenge.wildcard = auth.get.wildcard ? auth.get.wildcard : false, chals.push(challenge));
}
}
return chals;
}