michael-o commented on code in PR #155: URL: https://github.com/apache/maven-scm/pull/155#discussion_r925692105
########## maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gittest/src/main/java/org/apache/maven/scm/provider/git/command/checkout/GitSshCheckOutCommandTckTest.java: ########## @@ -0,0 +1,185 @@ +package org.apache.maven.scm.provider.git.command.checkout; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +import java.io.IOException; +import java.io.Writer; +import java.nio.file.FileSystem; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.attribute.PosixFilePermissions; +import java.security.GeneralSecurityException; +import java.security.KeyPair; +import java.security.PrivateKey; +import java.security.SecureRandom; +import java.util.Collections; + +import org.apache.maven.scm.provider.ScmProviderRepositoryWithHost; +import org.apache.maven.scm.provider.git.GitScmTestUtils; +import org.apache.maven.scm.repository.ScmRepository; +import org.apache.maven.scm.tck.command.checkout.CheckOutCommandTckTest; +import org.apache.sshd.common.config.keys.KeyUtils; +import org.apache.sshd.git.GitLocationResolver; +import org.apache.sshd.git.pack.GitPackCommandFactory; +import org.apache.sshd.server.SshServer; +import org.apache.sshd.server.auth.pubkey.KeySetPublickeyAuthenticator; +import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator; +import org.apache.sshd.server.session.ServerSession; +import org.apache.sshd.util.test.CommonTestSupportUtils; +import org.apache.sshd.util.test.CoreTestSupportUtils; +import org.bouncycastle.jce.provider.BouncyCastleProvider; +import org.bouncycastle.openssl.PKCS8Generator; +import org.bouncycastle.openssl.jcajce.JcaPEMWriter; +import org.bouncycastle.openssl.jcajce.JcaPKCS8Generator; +import org.bouncycastle.openssl.jcajce.JceOpenSSLPKCS8EncryptorBuilder; +import org.bouncycastle.operator.OperatorCreationException; +import org.bouncycastle.operator.OutputEncryptor; +import org.bouncycastle.util.io.pem.PemObject; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +/** + * + */ +public abstract class GitSshCheckOutCommandTckTest + extends CheckOutCommandTckTest +{ + protected final SshServer sshServer; + protected final KeyPair keyPair; + + @Rule + public TemporaryFolder tmpDirectory = new TemporaryFolder(); + + protected GitSshCheckOutCommandTckTest() throws GeneralSecurityException + { + sshServer = CoreTestSupportUtils.setupTestServer( getClass() ); + keyPair = CommonTestSupportUtils.generateKeyPair( KeyUtils.RSA_ALGORITHM, 2048 ); + PublickeyAuthenticator authenticator = new KeySetPublickeyAuthenticator( "onlykey", + Collections.singletonList( keyPair.getPublic() ) ); + sshServer.setPublickeyAuthenticator( authenticator ); + } + + static void writePrivateKeyAsPkcs8( Path file, PrivateKey privateKey, String passphrase ) + throws IOException, OperatorCreationException + { + final OutputEncryptor encryptor; + // encryption only optional + if ( passphrase != null ) + { + //encrypted form of PKCS#8 file Review Comment: I'd really try with an key gerated by OpenSSH directly or PuTTY and see how it goes. BTW, other components store a JKS which is valid for two years. I guess, it'd be fine to have the key pre-created. I wouldn't object. After all, the target of this IT is not to create a key, but to use a preexisting one to authenticate through SSH. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
