@electerm/ssh2 1.16.2 → 1.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/client.js +41 -0
- package/lib/protocol/Protocol.js +76 -16
- package/lib/protocol/certificateAuth.js +104 -0
- package/lib/protocol/crypto/build/Makefile +347 -0
- package/lib/protocol/crypto/build/Release/.deps/Release/obj.target/sshcrypto/src/binding.o.d +251 -0
- package/lib/protocol/crypto/build/Release/.deps/Release/sshcrypto.node.d +1 -0
- package/lib/protocol/crypto/build/Release/obj.target/sshcrypto/src/binding.o +0 -0
- package/lib/protocol/crypto/build/Release/sshcrypto.node +0 -0
- package/lib/protocol/crypto/build/binding.Makefile +6 -0
- package/lib/protocol/crypto/build/gyp-mac-tool +768 -0
- package/lib/protocol/crypto/build/sshcrypto.target.mk +191 -0
- package/lib/protocol/crypto/src/binding.cc +24 -48
- package/lib/protocol/sshCertificate.js +243 -0
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -84,6 +84,7 @@ class Client extends EventEmitter {
|
|
|
84
84
|
username: undefined,
|
|
85
85
|
password: undefined,
|
|
86
86
|
privateKey: undefined,
|
|
87
|
+
certificate: undefined,
|
|
87
88
|
tryKeyboard: undefined,
|
|
88
89
|
agent: undefined,
|
|
89
90
|
allowAgentFwd: undefined,
|
|
@@ -209,6 +210,10 @@ class Client extends EventEmitter {
|
|
|
209
210
|
|| Buffer.isBuffer(cfg.privateKey)
|
|
210
211
|
? cfg.privateKey
|
|
211
212
|
: undefined);
|
|
213
|
+
this.config.certificate = (typeof cfg.certificate === 'string'
|
|
214
|
+
|| Buffer.isBuffer(cfg.certificate)
|
|
215
|
+
? cfg.certificate
|
|
216
|
+
: undefined);
|
|
212
217
|
this.config.localHostname = (typeof cfg.localHostname === 'string'
|
|
213
218
|
? cfg.localHostname
|
|
214
219
|
: undefined);
|
|
@@ -268,6 +273,42 @@ class Client extends EventEmitter {
|
|
|
268
273
|
'privateKey value does not contain a (valid) private key'
|
|
269
274
|
);
|
|
270
275
|
}
|
|
276
|
+
|
|
277
|
+
// Wrap with certificate if provided
|
|
278
|
+
if (this.config.certificate) {
|
|
279
|
+
const { wrapKeyWithCertificate } = require('./protocol/certificateAuth.js');
|
|
280
|
+
let certBuffer = this.config.certificate;
|
|
281
|
+
|
|
282
|
+
// Handle string or buffer that contains OpenSSH public key format
|
|
283
|
+
let certStr;
|
|
284
|
+
if (typeof certBuffer === 'string') {
|
|
285
|
+
certStr = certBuffer.trim();
|
|
286
|
+
} else if (Buffer.isBuffer(certBuffer)) {
|
|
287
|
+
// Check if it's text format (starts with ssh-) or binary
|
|
288
|
+
const firstBytes = certBuffer.slice(0, 4).toString('utf8');
|
|
289
|
+
if (firstBytes.startsWith('ssh-') || firstBytes.startsWith('ecds')) {
|
|
290
|
+
certStr = certBuffer.toString('utf8').trim();
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
if (certStr) {
|
|
295
|
+
// Parse OpenSSH public key format: "type base64data [comment]"
|
|
296
|
+
const parts = certStr.split(/\s+/);
|
|
297
|
+
if (parts.length >= 2) {
|
|
298
|
+
try {
|
|
299
|
+
certBuffer = Buffer.from(parts[1], 'base64');
|
|
300
|
+
} catch (err) {
|
|
301
|
+
throw new Error(`Cannot parse certificate: ${err.message}`);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const wrappedKey = wrapKeyWithCertificate(privateKey, certBuffer);
|
|
307
|
+
if (wrappedKey instanceof Error) {
|
|
308
|
+
throw new Error(`Cannot wrap key with certificate: ${wrappedKey.message}`);
|
|
309
|
+
}
|
|
310
|
+
privateKey = wrappedKey;
|
|
311
|
+
}
|
|
271
312
|
}
|
|
272
313
|
|
|
273
314
|
let hostVerifier;
|
package/lib/protocol/Protocol.js
CHANGED
|
@@ -632,31 +632,88 @@ class Protocol {
|
|
|
632
632
|
if (this._server)
|
|
633
633
|
throw new Error('Client-only method called in server mode');
|
|
634
634
|
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
635
|
+
const origPubKey = pubKey;
|
|
636
|
+
|
|
637
|
+
// Only parse if it's not already a parsed key object
|
|
638
|
+
// Check for common key object properties
|
|
639
|
+
if (typeof pubKey !== 'object' || pubKey === null ||
|
|
640
|
+
typeof pubKey.type !== 'string' || typeof pubKey.getPublicSSH !== 'function') {
|
|
641
|
+
pubKey = parseKey(pubKey);
|
|
642
|
+
if (pubKey instanceof Error)
|
|
643
|
+
throw new Error('Invalid key');
|
|
644
|
+
}
|
|
638
645
|
|
|
639
646
|
let keyType = pubKey.type;
|
|
647
|
+
|
|
648
|
+
// Check if this is a certificate-wrapped key
|
|
649
|
+
let pubKeyData = pubKey.getPublicSSH();
|
|
650
|
+
let isCertificate = false;
|
|
651
|
+
if (pubKey.getCertificateBuffer) {
|
|
652
|
+
// This is a CertificateKey, use the certificate data instead
|
|
653
|
+
pubKeyData = pubKey.getCertificateBuffer();
|
|
654
|
+
isCertificate = true;
|
|
655
|
+
this._debug && this._debug('Using SSH certificate for authentication');
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
// Upgrade RSA to SHA2 variants if server supports them
|
|
659
|
+
// signAlgo is the actual algorithm used for signing
|
|
660
|
+
// NOTE: Order must match getKeyAlgos() in client.js - rsa-sha2-256 first
|
|
661
|
+
let signAlgo = keyType;
|
|
640
662
|
if (keyType === 'ssh-rsa') {
|
|
641
|
-
for (const algo of ['rsa-sha2-
|
|
663
|
+
for (const algo of ['rsa-sha2-256', 'rsa-sha2-512']) {
|
|
642
664
|
if (this._remoteHostKeyAlgorithms.includes(algo)) {
|
|
643
|
-
|
|
665
|
+
signAlgo = algo;
|
|
644
666
|
break;
|
|
645
667
|
}
|
|
646
668
|
}
|
|
647
669
|
}
|
|
648
|
-
|
|
670
|
+
|
|
671
|
+
// For certificates, append the cert suffix to the algorithm for the packet
|
|
672
|
+
// but keep signAlgo as the base signing algorithm
|
|
673
|
+
if (isCertificate) {
|
|
674
|
+
// Map the signing algorithm to certificate algorithm
|
|
675
|
+
// e.g., rsa-sha2-512 -> rsa-sha2-512-cert-v01@openssh.com
|
|
676
|
+
if (signAlgo === 'rsa-sha2-512') {
|
|
677
|
+
keyType = 'rsa-sha2-512-cert-v01@openssh.com';
|
|
678
|
+
} else if (signAlgo === 'rsa-sha2-256') {
|
|
679
|
+
keyType = 'rsa-sha2-256-cert-v01@openssh.com';
|
|
680
|
+
} else if (signAlgo === 'ssh-rsa' || keyType === 'ssh-rsa') {
|
|
681
|
+
keyType = 'ssh-rsa-cert-v01@openssh.com';
|
|
682
|
+
} else if (keyType === 'ssh-dss') {
|
|
683
|
+
keyType = 'ssh-dss-cert-v01@openssh.com';
|
|
684
|
+
} else if (keyType === 'ecdsa-sha2-nistp256') {
|
|
685
|
+
keyType = 'ecdsa-sha2-nistp256-cert-v01@openssh.com';
|
|
686
|
+
} else if (keyType === 'ecdsa-sha2-nistp384') {
|
|
687
|
+
keyType = 'ecdsa-sha2-nistp384-cert-v01@openssh.com';
|
|
688
|
+
} else if (keyType === 'ecdsa-sha2-nistp521') {
|
|
689
|
+
keyType = 'ecdsa-sha2-nistp521-cert-v01@openssh.com';
|
|
690
|
+
} else if (keyType === 'ssh-ed25519') {
|
|
691
|
+
keyType = 'ssh-ed25519-cert-v01@openssh.com';
|
|
692
|
+
}
|
|
693
|
+
this._debug && this._debug(`Certificate key algorithm: ${keyType}`);
|
|
694
|
+
} else {
|
|
695
|
+
// For non-certificates, keyType should be signAlgo
|
|
696
|
+
keyType = signAlgo;
|
|
697
|
+
}
|
|
649
698
|
|
|
650
699
|
if (typeof keyAlgo === 'function') {
|
|
651
700
|
cbSign = keyAlgo;
|
|
652
701
|
keyAlgo = undefined;
|
|
653
702
|
}
|
|
654
|
-
|
|
703
|
+
|
|
704
|
+
// For certificates, we must use the certificate algorithm regardless of what was passed
|
|
705
|
+
if (isCertificate) {
|
|
706
|
+
keyAlgo = keyType;
|
|
707
|
+
} else if (!keyAlgo) {
|
|
655
708
|
keyAlgo = keyType;
|
|
709
|
+
}
|
|
656
710
|
|
|
657
711
|
const userLen = Buffer.byteLength(username);
|
|
658
712
|
const algoLen = Buffer.byteLength(keyAlgo);
|
|
659
|
-
|
|
713
|
+
// For certificates, signAlgo is the base signing algorithm (e.g., rsa-sha2-512)
|
|
714
|
+
// For non-certificates, signAlgo equals keyAlgo
|
|
715
|
+
const signAlgoLen = Buffer.byteLength(signAlgo);
|
|
716
|
+
const pubKeyLen = pubKeyData.length;
|
|
660
717
|
const sessionID = this._kex.sessionID;
|
|
661
718
|
const sesLen = sessionID.length;
|
|
662
719
|
const payloadLen =
|
|
@@ -692,7 +749,7 @@ class Protocol {
|
|
|
692
749
|
packet.utf8Write(keyAlgo, p += 4, algoLen);
|
|
693
750
|
|
|
694
751
|
writeUInt32BE(packet, pubKeyLen, p += algoLen);
|
|
695
|
-
packet.set(
|
|
752
|
+
packet.set(pubKeyData, p += 4);
|
|
696
753
|
|
|
697
754
|
if (!cbSign) {
|
|
698
755
|
this._authsQueue.push('publickey');
|
|
@@ -705,7 +762,7 @@ class Protocol {
|
|
|
705
762
|
}
|
|
706
763
|
|
|
707
764
|
cbSign(packet, (signature) => {
|
|
708
|
-
signature = convertSignature(signature,
|
|
765
|
+
signature = convertSignature(signature, signAlgo);
|
|
709
766
|
if (signature === false)
|
|
710
767
|
throw new Error('Error while converting handshake signature');
|
|
711
768
|
|
|
@@ -713,7 +770,7 @@ class Protocol {
|
|
|
713
770
|
p = this._packetRW.write.allocStart;
|
|
714
771
|
packet = this._packetRW.write.alloc(
|
|
715
772
|
1 + 4 + userLen + 4 + 14 + 4 + 9 + 1 + 4 + algoLen + 4 + pubKeyLen + 4
|
|
716
|
-
+ 4 +
|
|
773
|
+
+ 4 + signAlgoLen + 4 + sigLen
|
|
717
774
|
);
|
|
718
775
|
|
|
719
776
|
// TODO: simply copy from original "packet" to new `packet` to avoid
|
|
@@ -735,14 +792,17 @@ class Protocol {
|
|
|
735
792
|
packet.utf8Write(keyAlgo, p += 4, algoLen);
|
|
736
793
|
|
|
737
794
|
writeUInt32BE(packet, pubKeyLen, p += algoLen);
|
|
738
|
-
packet.set(
|
|
795
|
+
packet.set(pubKeyData, p += 4);
|
|
739
796
|
|
|
740
|
-
|
|
797
|
+
// Signature blob: length-prefixed (algorithm string + raw signature)
|
|
798
|
+
// For RSA signatures, use the base signing algorithm (without cert suffix)
|
|
799
|
+
// The cert suffix is only used in the public key algorithm field of the main packet
|
|
800
|
+
writeUInt32BE(packet, 4 + signAlgoLen + 4 + sigLen, p += pubKeyLen);
|
|
741
801
|
|
|
742
|
-
writeUInt32BE(packet,
|
|
743
|
-
packet.utf8Write(
|
|
802
|
+
writeUInt32BE(packet, signAlgoLen, p += 4);
|
|
803
|
+
packet.utf8Write(signAlgo, p += 4, signAlgoLen);
|
|
744
804
|
|
|
745
|
-
writeUInt32BE(packet, sigLen, p +=
|
|
805
|
+
writeUInt32BE(packet, sigLen, p += signAlgoLen);
|
|
746
806
|
packet.set(signature, p += 4);
|
|
747
807
|
|
|
748
808
|
// Servers shouldn't send packet type 60 in response to signed publickey
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
parseSSHCertificate,
|
|
5
|
+
isCertificate,
|
|
6
|
+
} = require('./sshCertificate.js');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Handle SSH certificate public key authentication
|
|
10
|
+
* This extends regular publickey auth to support certificates
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
class CertificateKey {
|
|
14
|
+
constructor(baseKey, certificate, certBuffer) {
|
|
15
|
+
this.baseKey = baseKey; // The underlying parsed key
|
|
16
|
+
this.certificate = certificate; // Parsed certificate data
|
|
17
|
+
this.certBuffer = certBuffer; // Raw certificate buffer
|
|
18
|
+
this.type = baseKey.type;
|
|
19
|
+
this.comment = baseKey.comment;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
isPrivateKey() {
|
|
23
|
+
return this.baseKey.isPrivateKey();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
getPublicPEM() {
|
|
27
|
+
return this.baseKey.getPublicPEM?.();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
getPublicSSH(algo) {
|
|
31
|
+
return this.baseKey.getPublicSSH?.(algo);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
sign(data, algo) {
|
|
35
|
+
return this.baseKey.sign(data, algo);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
verify(data, signature, algo) {
|
|
39
|
+
return this.baseKey.verify(data, signature, algo);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
getCertificate() {
|
|
43
|
+
return this.certificate;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
getCertificateBuffer() {
|
|
47
|
+
return this.certBuffer;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Wrap a parsed key with certificate information
|
|
53
|
+
*/
|
|
54
|
+
function wrapKeyWithCertificate(key, certBuffer) {
|
|
55
|
+
if (!Buffer.isBuffer(certBuffer)) {
|
|
56
|
+
return new Error('Certificate must be a Buffer');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
// Verify this is a certificate
|
|
61
|
+
if (!isCertificate(certBuffer)) {
|
|
62
|
+
return new Error('Buffer does not appear to be a certificate');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Parse the certificate - it expects the complete buffer including type string
|
|
66
|
+
const certificate = parseSSHCertificate(certBuffer);
|
|
67
|
+
|
|
68
|
+
if (certificate instanceof Error) {
|
|
69
|
+
return certificate;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return new CertificateKey(key, certificate, certBuffer);
|
|
73
|
+
} catch (err) {
|
|
74
|
+
return err;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Extract certificate from OpenSSH public key format
|
|
80
|
+
* Returns { certBuffer, remainingData } or Error
|
|
81
|
+
*/
|
|
82
|
+
function extractCertificateFromData(data) {
|
|
83
|
+
if (!Buffer.isBuffer(data)) {
|
|
84
|
+
return new Error('Data must be a Buffer');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (!isCertificate(data)) {
|
|
88
|
+
return null; // Not a certificate
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
// The data is in binary SSH format: [type-len][type][data-len][data]...
|
|
93
|
+
// For a certificate, the entire data IS the certificate
|
|
94
|
+
return { certBuffer: data };
|
|
95
|
+
} catch (err) {
|
|
96
|
+
return err;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
module.exports = {
|
|
101
|
+
CertificateKey,
|
|
102
|
+
wrapKeyWithCertificate,
|
|
103
|
+
extractCertificateFromData,
|
|
104
|
+
};
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
# We borrow heavily from the kernel build setup, though we are simpler since
|
|
2
|
+
# we don't have Kconfig tweaking settings on us.
|
|
3
|
+
|
|
4
|
+
# The implicit make rules have it looking for RCS files, among other things.
|
|
5
|
+
# We instead explicitly write all the rules we care about.
|
|
6
|
+
# It's even quicker (saves ~200ms) to pass -r on the command line.
|
|
7
|
+
MAKEFLAGS=-r
|
|
8
|
+
|
|
9
|
+
# The source directory tree.
|
|
10
|
+
srcdir := ..
|
|
11
|
+
abs_srcdir := $(abspath $(srcdir))
|
|
12
|
+
|
|
13
|
+
# The name of the builddir.
|
|
14
|
+
builddir_name ?= .
|
|
15
|
+
|
|
16
|
+
# The V=1 flag on command line makes us verbosely print command lines.
|
|
17
|
+
ifdef V
|
|
18
|
+
quiet=
|
|
19
|
+
else
|
|
20
|
+
quiet=quiet_
|
|
21
|
+
endif
|
|
22
|
+
|
|
23
|
+
# Specify BUILDTYPE=Release on the command line for a release build.
|
|
24
|
+
BUILDTYPE ?= Release
|
|
25
|
+
|
|
26
|
+
# Directory all our build output goes into.
|
|
27
|
+
# Note that this must be two directories beneath src/ for unit tests to pass,
|
|
28
|
+
# as they reach into the src/ directory for data with relative paths.
|
|
29
|
+
builddir ?= $(builddir_name)/$(BUILDTYPE)
|
|
30
|
+
abs_builddir := $(abspath $(builddir))
|
|
31
|
+
depsdir := $(builddir)/.deps
|
|
32
|
+
|
|
33
|
+
# Object output directory.
|
|
34
|
+
obj := $(builddir)/obj
|
|
35
|
+
abs_obj := $(abspath $(obj))
|
|
36
|
+
|
|
37
|
+
# We build up a list of every single one of the targets so we can slurp in the
|
|
38
|
+
# generated dependency rule Makefiles in one pass.
|
|
39
|
+
all_deps :=
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
CC.target ?= $(CC)
|
|
44
|
+
CFLAGS.target ?= $(CPPFLAGS) $(CFLAGS)
|
|
45
|
+
CXX.target ?= $(CXX)
|
|
46
|
+
CXXFLAGS.target ?= $(CPPFLAGS) $(CXXFLAGS)
|
|
47
|
+
LINK.target ?= $(LINK)
|
|
48
|
+
LDFLAGS.target ?= $(LDFLAGS)
|
|
49
|
+
AR.target ?= $(AR)
|
|
50
|
+
PLI.target ?= pli
|
|
51
|
+
|
|
52
|
+
# C++ apps need to be linked with g++.
|
|
53
|
+
LINK ?= $(CXX.target)
|
|
54
|
+
|
|
55
|
+
# TODO(evan): move all cross-compilation logic to gyp-time so we don't need
|
|
56
|
+
# to replicate this environment fallback in make as well.
|
|
57
|
+
CC.host ?= gcc
|
|
58
|
+
CFLAGS.host ?= $(CPPFLAGS_host) $(CFLAGS_host)
|
|
59
|
+
CXX.host ?= g++
|
|
60
|
+
CXXFLAGS.host ?= $(CPPFLAGS_host) $(CXXFLAGS_host)
|
|
61
|
+
LINK.host ?= $(CXX.host)
|
|
62
|
+
LDFLAGS.host ?= $(LDFLAGS_host)
|
|
63
|
+
AR.host ?= ar
|
|
64
|
+
PLI.host ?= pli
|
|
65
|
+
|
|
66
|
+
# Define a dir function that can handle spaces.
|
|
67
|
+
# http://www.gnu.org/software/make/manual/make.html#Syntax-of-Functions
|
|
68
|
+
# "leading spaces cannot appear in the text of the first argument as written.
|
|
69
|
+
# These characters can be put into the argument value by variable substitution."
|
|
70
|
+
empty :=
|
|
71
|
+
space := $(empty) $(empty)
|
|
72
|
+
|
|
73
|
+
# http://stackoverflow.com/questions/1189781/using-make-dir-or-notdir-on-a-path-with-spaces
|
|
74
|
+
replace_spaces = $(subst $(space),?,$1)
|
|
75
|
+
unreplace_spaces = $(subst ?,$(space),$1)
|
|
76
|
+
dirx = $(call unreplace_spaces,$(dir $(call replace_spaces,$1)))
|
|
77
|
+
|
|
78
|
+
# Flags to make gcc output dependency info. Note that you need to be
|
|
79
|
+
# careful here to use the flags that ccache and distcc can understand.
|
|
80
|
+
# We write to a dep file on the side first and then rename at the end
|
|
81
|
+
# so we can't end up with a broken dep file.
|
|
82
|
+
depfile = $(depsdir)/$(call replace_spaces,$@).d
|
|
83
|
+
DEPFLAGS = -MMD -MF $(depfile).raw
|
|
84
|
+
|
|
85
|
+
# We have to fixup the deps output in a few ways.
|
|
86
|
+
# (1) the file output should mention the proper .o file.
|
|
87
|
+
# ccache or distcc lose the path to the target, so we convert a rule of
|
|
88
|
+
# the form:
|
|
89
|
+
# foobar.o: DEP1 DEP2
|
|
90
|
+
# into
|
|
91
|
+
# path/to/foobar.o: DEP1 DEP2
|
|
92
|
+
# (2) we want missing files not to cause us to fail to build.
|
|
93
|
+
# We want to rewrite
|
|
94
|
+
# foobar.o: DEP1 DEP2 \
|
|
95
|
+
# DEP3
|
|
96
|
+
# to
|
|
97
|
+
# DEP1:
|
|
98
|
+
# DEP2:
|
|
99
|
+
# DEP3:
|
|
100
|
+
# so if the files are missing, they're just considered phony rules.
|
|
101
|
+
# We have to do some pretty insane escaping to get those backslashes
|
|
102
|
+
# and dollar signs past make, the shell, and sed at the same time.
|
|
103
|
+
# Doesn't work with spaces, but that's fine: .d files have spaces in
|
|
104
|
+
# their names replaced with other characters.
|
|
105
|
+
define fixup_dep
|
|
106
|
+
# The depfile may not exist if the input file didn't have any #includes.
|
|
107
|
+
touch $(depfile).raw
|
|
108
|
+
# Fixup path as in (1).
|
|
109
|
+
sed -e "s|^$(notdir $@)|$@|" $(depfile).raw >> $(depfile)
|
|
110
|
+
# Add extra rules as in (2).
|
|
111
|
+
# We remove slashes and replace spaces with new lines;
|
|
112
|
+
# remove blank lines;
|
|
113
|
+
# delete the first line and append a colon to the remaining lines.
|
|
114
|
+
sed -e 's|\\||' -e 'y| |\n|' $(depfile).raw |\
|
|
115
|
+
grep -v '^$$' |\
|
|
116
|
+
sed -e 1d -e 's|$$|:|' \
|
|
117
|
+
>> $(depfile)
|
|
118
|
+
rm $(depfile).raw
|
|
119
|
+
endef
|
|
120
|
+
|
|
121
|
+
# Command definitions:
|
|
122
|
+
# - cmd_foo is the actual command to run;
|
|
123
|
+
# - quiet_cmd_foo is the brief-output summary of the command.
|
|
124
|
+
|
|
125
|
+
quiet_cmd_cc = CC($(TOOLSET)) $@
|
|
126
|
+
cmd_cc = $(CC.$(TOOLSET)) -o $@ $< $(GYP_CFLAGS) $(DEPFLAGS) $(CFLAGS.$(TOOLSET)) -c
|
|
127
|
+
|
|
128
|
+
quiet_cmd_cxx = CXX($(TOOLSET)) $@
|
|
129
|
+
cmd_cxx = $(CXX.$(TOOLSET)) -o $@ $< $(GYP_CXXFLAGS) $(DEPFLAGS) $(CXXFLAGS.$(TOOLSET)) -c
|
|
130
|
+
|
|
131
|
+
quiet_cmd_objc = CXX($(TOOLSET)) $@
|
|
132
|
+
cmd_objc = $(CC.$(TOOLSET)) $(GYP_OBJCFLAGS) $(DEPFLAGS) -c -o $@ $<
|
|
133
|
+
|
|
134
|
+
quiet_cmd_objcxx = CXX($(TOOLSET)) $@
|
|
135
|
+
cmd_objcxx = $(CXX.$(TOOLSET)) $(GYP_OBJCXXFLAGS) $(DEPFLAGS) -c -o $@ $<
|
|
136
|
+
|
|
137
|
+
# Commands for precompiled header files.
|
|
138
|
+
quiet_cmd_pch_c = CXX($(TOOLSET)) $@
|
|
139
|
+
cmd_pch_c = $(CC.$(TOOLSET)) $(GYP_PCH_CFLAGS) $(DEPFLAGS) $(CXXFLAGS.$(TOOLSET)) -c -o $@ $<
|
|
140
|
+
quiet_cmd_pch_cc = CXX($(TOOLSET)) $@
|
|
141
|
+
cmd_pch_cc = $(CC.$(TOOLSET)) $(GYP_PCH_CXXFLAGS) $(DEPFLAGS) $(CXXFLAGS.$(TOOLSET)) -c -o $@ $<
|
|
142
|
+
quiet_cmd_pch_m = CXX($(TOOLSET)) $@
|
|
143
|
+
cmd_pch_m = $(CC.$(TOOLSET)) $(GYP_PCH_OBJCFLAGS) $(DEPFLAGS) -c -o $@ $<
|
|
144
|
+
quiet_cmd_pch_mm = CXX($(TOOLSET)) $@
|
|
145
|
+
cmd_pch_mm = $(CC.$(TOOLSET)) $(GYP_PCH_OBJCXXFLAGS) $(DEPFLAGS) -c -o $@ $<
|
|
146
|
+
|
|
147
|
+
# gyp-mac-tool is written next to the root Makefile by gyp.
|
|
148
|
+
# Use $(4) for the command, since $(2) and $(3) are used as flag by do_cmd
|
|
149
|
+
# already.
|
|
150
|
+
quiet_cmd_mac_tool = MACTOOL $(4) $<
|
|
151
|
+
cmd_mac_tool = /usr/local/opt/python@3.14/bin/python3.14 gyp-mac-tool $(4) $< "$@"
|
|
152
|
+
|
|
153
|
+
quiet_cmd_mac_package_framework = PACKAGE FRAMEWORK $@
|
|
154
|
+
cmd_mac_package_framework = /usr/local/opt/python@3.14/bin/python3.14 gyp-mac-tool package-framework "$@" $(4)
|
|
155
|
+
|
|
156
|
+
quiet_cmd_infoplist = INFOPLIST $@
|
|
157
|
+
cmd_infoplist = $(CC.$(TOOLSET)) -E -P -Wno-trigraphs -x c $(INFOPLIST_DEFINES) "$<" -o "$@"
|
|
158
|
+
|
|
159
|
+
quiet_cmd_touch = TOUCH $@
|
|
160
|
+
cmd_touch = touch $@
|
|
161
|
+
|
|
162
|
+
quiet_cmd_copy = COPY $@
|
|
163
|
+
# send stderr to /dev/null to ignore messages when linking directories.
|
|
164
|
+
cmd_copy = ln -f "$<" "$@" 2>/dev/null || (rm -rf "$@" && cp -af "$<" "$@")
|
|
165
|
+
|
|
166
|
+
quiet_cmd_symlink = SYMLINK $@
|
|
167
|
+
cmd_symlink = ln -sf "$<" "$@"
|
|
168
|
+
|
|
169
|
+
quiet_cmd_alink = LIBTOOL-STATIC $@
|
|
170
|
+
cmd_alink = rm -f $@ && /usr/local/opt/python@3.14/bin/python3.14 gyp-mac-tool filter-libtool libtool $(GYP_LIBTOOLFLAGS) -static -o $@ $(filter %.o,$^)
|
|
171
|
+
|
|
172
|
+
quiet_cmd_link = LINK($(TOOLSET)) $@
|
|
173
|
+
cmd_link = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o "$@" $(LD_INPUTS) $(LIBS)
|
|
174
|
+
|
|
175
|
+
quiet_cmd_solink = SOLINK($(TOOLSET)) $@
|
|
176
|
+
cmd_solink = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o "$@" $(LD_INPUTS) $(LIBS)
|
|
177
|
+
|
|
178
|
+
quiet_cmd_solink_module = SOLINK_MODULE($(TOOLSET)) $@
|
|
179
|
+
cmd_solink_module = $(LINK.$(TOOLSET)) -bundle $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(filter-out FORCE_DO_CMD, $^) $(LIBS)
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
# Define an escape_quotes function to escape single quotes.
|
|
183
|
+
# This allows us to handle quotes properly as long as we always use
|
|
184
|
+
# use single quotes and escape_quotes.
|
|
185
|
+
escape_quotes = $(subst ','\'',$(1))
|
|
186
|
+
# This comment is here just to include a ' to unconfuse syntax highlighting.
|
|
187
|
+
# Define an escape_vars function to escape '$' variable syntax.
|
|
188
|
+
# This allows us to read/write command lines with shell variables (e.g.
|
|
189
|
+
# $LD_LIBRARY_PATH), without triggering make substitution.
|
|
190
|
+
escape_vars = $(subst $$,$$$$,$(1))
|
|
191
|
+
# Helper that expands to a shell command to echo a string exactly as it is in
|
|
192
|
+
# make. This uses printf instead of echo because printf's behaviour with respect
|
|
193
|
+
# to escape sequences is more portable than echo's across different shells
|
|
194
|
+
# (e.g., dash, bash).
|
|
195
|
+
exact_echo = printf '%s\n' '$(call escape_quotes,$(1))'
|
|
196
|
+
|
|
197
|
+
# Helper to compare the command we're about to run against the command
|
|
198
|
+
# we logged the last time we ran the command. Produces an empty
|
|
199
|
+
# string (false) when the commands match.
|
|
200
|
+
# Tricky point: Make has no string-equality test function.
|
|
201
|
+
# The kernel uses the following, but it seems like it would have false
|
|
202
|
+
# positives, where one string reordered its arguments.
|
|
203
|
+
# arg_check = $(strip $(filter-out $(cmd_$(1)), $(cmd_$@)) \
|
|
204
|
+
# $(filter-out $(cmd_$@), $(cmd_$(1))))
|
|
205
|
+
# We instead substitute each for the empty string into the other, and
|
|
206
|
+
# say they're equal if both substitutions produce the empty string.
|
|
207
|
+
# .d files contain ? instead of spaces, take that into account.
|
|
208
|
+
command_changed = $(or $(subst $(cmd_$(1)),,$(cmd_$(call replace_spaces,$@))),\
|
|
209
|
+
$(subst $(cmd_$(call replace_spaces,$@)),,$(cmd_$(1))))
|
|
210
|
+
|
|
211
|
+
# Helper that is non-empty when a prerequisite changes.
|
|
212
|
+
# Normally make does this implicitly, but we force rules to always run
|
|
213
|
+
# so we can check their command lines.
|
|
214
|
+
# $? -- new prerequisites
|
|
215
|
+
# $| -- order-only dependencies
|
|
216
|
+
prereq_changed = $(filter-out FORCE_DO_CMD,$(filter-out $|,$?))
|
|
217
|
+
|
|
218
|
+
# Helper that executes all postbuilds until one fails.
|
|
219
|
+
define do_postbuilds
|
|
220
|
+
@E=0;\
|
|
221
|
+
for p in $(POSTBUILDS); do\
|
|
222
|
+
eval $$p;\
|
|
223
|
+
E=$$?;\
|
|
224
|
+
if [ $$E -ne 0 ]; then\
|
|
225
|
+
break;\
|
|
226
|
+
fi;\
|
|
227
|
+
done;\
|
|
228
|
+
if [ $$E -ne 0 ]; then\
|
|
229
|
+
rm -rf "$@";\
|
|
230
|
+
exit $$E;\
|
|
231
|
+
fi
|
|
232
|
+
endef
|
|
233
|
+
|
|
234
|
+
# do_cmd: run a command via the above cmd_foo names, if necessary.
|
|
235
|
+
# Should always run for a given target to handle command-line changes.
|
|
236
|
+
# Second argument, if non-zero, makes it do asm/C/C++ dependency munging.
|
|
237
|
+
# Third argument, if non-zero, makes it do POSTBUILDS processing.
|
|
238
|
+
# Note: We intentionally do NOT call dirx for depfile, since it contains ? for
|
|
239
|
+
# spaces already and dirx strips the ? characters.
|
|
240
|
+
define do_cmd
|
|
241
|
+
$(if $(or $(command_changed),$(prereq_changed)),
|
|
242
|
+
@$(call exact_echo, $($(quiet)cmd_$(1)))
|
|
243
|
+
@mkdir -p "$(call dirx,$@)" "$(dir $(depfile))"
|
|
244
|
+
$(if $(findstring flock,$(word 2,$(cmd_$1))),
|
|
245
|
+
@$(cmd_$(1))
|
|
246
|
+
@echo " $(quiet_cmd_$(1)): Finished",
|
|
247
|
+
@$(cmd_$(1))
|
|
248
|
+
)
|
|
249
|
+
@$(call exact_echo,$(call escape_vars,cmd_$(call replace_spaces,$@) := $(cmd_$(1)))) > $(depfile)
|
|
250
|
+
@$(if $(2),$(fixup_dep))
|
|
251
|
+
$(if $(and $(3), $(POSTBUILDS)),
|
|
252
|
+
$(call do_postbuilds)
|
|
253
|
+
)
|
|
254
|
+
)
|
|
255
|
+
endef
|
|
256
|
+
|
|
257
|
+
# Declare the "all" target first so it is the default,
|
|
258
|
+
# even though we don't have the deps yet.
|
|
259
|
+
.PHONY: all
|
|
260
|
+
all:
|
|
261
|
+
|
|
262
|
+
# make looks for ways to re-generate included makefiles, but in our case, we
|
|
263
|
+
# don't have a direct way. Explicitly telling make that it has nothing to do
|
|
264
|
+
# for them makes it go faster.
|
|
265
|
+
%.d: ;
|
|
266
|
+
|
|
267
|
+
# Use FORCE_DO_CMD to force a target to run. Should be coupled with
|
|
268
|
+
# do_cmd.
|
|
269
|
+
.PHONY: FORCE_DO_CMD
|
|
270
|
+
FORCE_DO_CMD:
|
|
271
|
+
|
|
272
|
+
TOOLSET := target
|
|
273
|
+
# Suffix rules, putting all outputs into $(obj).
|
|
274
|
+
$(obj).$(TOOLSET)/%.o: $(srcdir)/%.c FORCE_DO_CMD
|
|
275
|
+
@$(call do_cmd,cc,1)
|
|
276
|
+
$(obj).$(TOOLSET)/%.o: $(srcdir)/%.cc FORCE_DO_CMD
|
|
277
|
+
@$(call do_cmd,cxx,1)
|
|
278
|
+
$(obj).$(TOOLSET)/%.o: $(srcdir)/%.cpp FORCE_DO_CMD
|
|
279
|
+
@$(call do_cmd,cxx,1)
|
|
280
|
+
$(obj).$(TOOLSET)/%.o: $(srcdir)/%.cxx FORCE_DO_CMD
|
|
281
|
+
@$(call do_cmd,cxx,1)
|
|
282
|
+
$(obj).$(TOOLSET)/%.o: $(srcdir)/%.m FORCE_DO_CMD
|
|
283
|
+
@$(call do_cmd,objc,1)
|
|
284
|
+
$(obj).$(TOOLSET)/%.o: $(srcdir)/%.mm FORCE_DO_CMD
|
|
285
|
+
@$(call do_cmd,objcxx,1)
|
|
286
|
+
$(obj).$(TOOLSET)/%.o: $(srcdir)/%.s FORCE_DO_CMD
|
|
287
|
+
@$(call do_cmd,cc,1)
|
|
288
|
+
$(obj).$(TOOLSET)/%.o: $(srcdir)/%.S FORCE_DO_CMD
|
|
289
|
+
@$(call do_cmd,cc,1)
|
|
290
|
+
|
|
291
|
+
# Try building from generated source, too.
|
|
292
|
+
$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.c FORCE_DO_CMD
|
|
293
|
+
@$(call do_cmd,cc,1)
|
|
294
|
+
$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.cc FORCE_DO_CMD
|
|
295
|
+
@$(call do_cmd,cxx,1)
|
|
296
|
+
$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.cpp FORCE_DO_CMD
|
|
297
|
+
@$(call do_cmd,cxx,1)
|
|
298
|
+
$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.cxx FORCE_DO_CMD
|
|
299
|
+
@$(call do_cmd,cxx,1)
|
|
300
|
+
$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.m FORCE_DO_CMD
|
|
301
|
+
@$(call do_cmd,objc,1)
|
|
302
|
+
$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.mm FORCE_DO_CMD
|
|
303
|
+
@$(call do_cmd,objcxx,1)
|
|
304
|
+
$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.s FORCE_DO_CMD
|
|
305
|
+
@$(call do_cmd,cc,1)
|
|
306
|
+
$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.S FORCE_DO_CMD
|
|
307
|
+
@$(call do_cmd,cc,1)
|
|
308
|
+
|
|
309
|
+
$(obj).$(TOOLSET)/%.o: $(obj)/%.c FORCE_DO_CMD
|
|
310
|
+
@$(call do_cmd,cc,1)
|
|
311
|
+
$(obj).$(TOOLSET)/%.o: $(obj)/%.cc FORCE_DO_CMD
|
|
312
|
+
@$(call do_cmd,cxx,1)
|
|
313
|
+
$(obj).$(TOOLSET)/%.o: $(obj)/%.cpp FORCE_DO_CMD
|
|
314
|
+
@$(call do_cmd,cxx,1)
|
|
315
|
+
$(obj).$(TOOLSET)/%.o: $(obj)/%.cxx FORCE_DO_CMD
|
|
316
|
+
@$(call do_cmd,cxx,1)
|
|
317
|
+
$(obj).$(TOOLSET)/%.o: $(obj)/%.m FORCE_DO_CMD
|
|
318
|
+
@$(call do_cmd,objc,1)
|
|
319
|
+
$(obj).$(TOOLSET)/%.o: $(obj)/%.mm FORCE_DO_CMD
|
|
320
|
+
@$(call do_cmd,objcxx,1)
|
|
321
|
+
$(obj).$(TOOLSET)/%.o: $(obj)/%.s FORCE_DO_CMD
|
|
322
|
+
@$(call do_cmd,cc,1)
|
|
323
|
+
$(obj).$(TOOLSET)/%.o: $(obj)/%.S FORCE_DO_CMD
|
|
324
|
+
@$(call do_cmd,cc,1)
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
ifeq ($(strip $(foreach prefix,$(NO_LOAD),\
|
|
328
|
+
$(findstring $(join ^,$(prefix)),\
|
|
329
|
+
$(join ^,sshcrypto.target.mk)))),)
|
|
330
|
+
include sshcrypto.target.mk
|
|
331
|
+
endif
|
|
332
|
+
|
|
333
|
+
quiet_cmd_regen_makefile = ACTION Regenerating $@
|
|
334
|
+
cmd_regen_makefile = cd $(srcdir); /Users/zxd/.nvm/versions/node/v22.19.0/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py -fmake --ignore-environment "-Dlibrary=shared_library" "-Dvisibility=default" "-Dnode_root_dir=/Users/zxd/Library/Caches/node-gyp/22.19.0" "-Dnode_gyp_dir=/Users/zxd/.nvm/versions/node/v22.19.0/lib/node_modules/npm/node_modules/node-gyp" "-Dnode_lib_file=/Users/zxd/Library/Caches/node-gyp/22.19.0/<(target_arch)/node.lib" "-Dmodule_root_dir=/Users/zxd/dev/ssh2/lib/protocol/crypto" "-Dnode_engine=v8" "--depth=." "-Goutput_dir=." "--generator-output=build" -I/Users/zxd/dev/ssh2/lib/protocol/crypto/build/config.gypi -I/Users/zxd/.nvm/versions/node/v22.19.0/lib/node_modules/npm/node_modules/node-gyp/addon.gypi -I/Users/zxd/Library/Caches/node-gyp/22.19.0/include/node/common.gypi "--toplevel-dir=." binding.gyp
|
|
335
|
+
Makefile: $(srcdir)/binding.gyp $(srcdir)/../../../../../.nvm/versions/node/v22.19.0/lib/node_modules/npm/node_modules/node-gyp/addon.gypi $(srcdir)/../../../../../Library/Caches/node-gyp/22.19.0/include/node/common.gypi $(srcdir)/build/config.gypi
|
|
336
|
+
$(call do_cmd,regen_makefile)
|
|
337
|
+
|
|
338
|
+
# "all" is a concatenation of the "all" targets from all the included
|
|
339
|
+
# sub-makefiles. This is just here to clarify.
|
|
340
|
+
all:
|
|
341
|
+
|
|
342
|
+
# Add in dependency-tracking rules. $(all_deps) is the list of every single
|
|
343
|
+
# target in our tree. Only consider the ones with .d (dependency) info:
|
|
344
|
+
d_files := $(wildcard $(foreach f,$(all_deps),$(depsdir)/$(f).d))
|
|
345
|
+
ifneq ($(d_files),)
|
|
346
|
+
include $(d_files)
|
|
347
|
+
endif
|