本文整理汇总了Java中com.jcraft.jsch.HostKeyRepository类的典型用法代码示例。如果您正苦于以下问题:Java HostKeyRepository类的具体用法?Java HostKeyRepository怎么用?Java HostKeyRepository使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HostKeyRepository类属于com.jcraft.jsch包,在下文中一共展示了HostKeyRepository类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getHostKeyRepository
import com.jcraft.jsch.HostKeyRepository; //导入依赖的package包/类
/**
* @param knownHostFile
* @return
* @throws JSchException
*/
private static HostKeyRepository getHostKeyRepository( String knownHostFile )
throws JSchException
{
JSch jsch = new JSch();
jsch.setKnownHosts( knownHostFile );
return jsch.getHostKeyRepository();
}
示例2: testKnownHostsFile
import com.jcraft.jsch.HostKeyRepository; //导入依赖的package包/类
@Test
public void testKnownHostsFile() throws Exception {
final JschBuilder builder = new JschBuilder();
builder.setKnownHostsFileName(knownHostsFile);
builder.setPrivateKeyFileName(privateKeyFile);
final JSch jsch = builder.build();
final HostKeyRepository knownHosts = jsch.getHostKeyRepository();
assertEquals(knownHostsFile,
knownHosts.getKnownHostsRepositoryID());
}
示例3: connect
import com.jcraft.jsch.HostKeyRepository; //导入依赖的package包/类
/**
* Enforce server reconnection (closes the current connection if it is still alive)
*/
public synchronized void connect() throws SFTPConnectionException {
//checkLocked();
try {
// Try to disconnect
this.disconnect();
// Open new connection
Logger.defaultLogger().info("Trying to connect to server : " + this.remoteServer + " ...");
debug("connect : connect", remoteServer);
JSch jsch = new JSch();
if (checkHostKey) {
HostKeyRepository hkr = jsch.getHostKeyRepository();
byte[] keybytes = this.getHostKeyAsByteArray();
if (keybytes == null) {
throw new SFTPConnectionException("Incorrect hostkey : " + this.getHostKeyAsString());
}
HostKey key = new HostKey(remoteServer, keybytes);
hkr.add(key, null);
jsch.setHostKeyRepository(hkr);
}
if (useCertificateAuth) {
if (certificateFileName == null || certificateFileName.trim().length() == 0 || ! FileSystemManager.exists(new File(certificateFileName))) {
throw new SFTPConnectionException("Certificate file not set or not found : " + certificateFileName);
} else {
Logger.defaultLogger().info("Using private key file : " + certificateFileName);
if (certificateFileName.toLowerCase().endsWith(".ppk")) {
Logger.defaultLogger().warn("Your private key file seems to be in PuTTY's \"ppk\" file format. Please convert it to the standard OpenSSH format (this can be done by using the \"puttygen.exe\" utility - see \"Convertions\" menu.)");
}
jsch.addIdentity(certificateFileName);
}
}
session = jsch.getSession(login, remoteServer, remotePort);
UserInfo ui = new DefaultUserInfo(this.password, certPassPhrase, certificateFileName);
session.setUserInfo(ui);
session.setDaemonThread(true);
session.setConfig("StrictHostKeyChecking", checkHostKey ? "yes":"no");
String preferredAuth;
String configuredPAuth = FrameworkConfiguration.getInstance().getSftpPreferredAuthOverride();
if (configuredPAuth != null && configuredPAuth.trim().length() != 0) {
preferredAuth = configuredPAuth;
} else {
preferredAuth = useCertificateAuth ? "publickey,password" : "password,publickey";
}
Logger.defaultLogger().fine("Authentication methods: " + preferredAuth);
session.setConfig("PreferredAuthentications", preferredAuth);
session.setTimeout(FrameworkConfiguration.getInstance().getSFTPTimeout());
Logger.defaultLogger().info("Trying to log in with user : " + this.login + " (" + (useCertificateAuth ? "certificate":"password") + ") ...");
debug("connect : login", login);
session.connect();
client = (ChannelSftp)session.openChannel("sftp");
client.connect();
this.connectionId = Util.getRndLong();
this.updateOpTime();
Logger.defaultLogger().info("Connected to server : " + this.remoteServer);
} catch (JSchException e) {
resetClient(e);
throw new SFTPConnectionException("Unable to connect to server : " + this.remoteServer + " (" + e.getMessage() + ")");
} finally {
clearCache();
}
}
示例4: configure
import com.jcraft.jsch.HostKeyRepository; //导入依赖的package包/类
@Override
protected void configure() {
install(RepositoryScope.module());
install(OperationScope.module());
bind(UserInfo.class).to(GUIUserInfo.class);
bind(ImageSession.class).toProvider(ImageSessionProvider.class).in(ContextSingleton.class);
bind(Repository.class).toProvider(RepositoryProvider.class);
bind(Ref.class).annotatedWith(named("branch")).toProvider(BranchRefProvider.class);
bind(AndroidAuthAgent.class).toProvider(AndroidAuthAgentProvider.class);
bind(GitAsyncTaskFactory.class).toProvider(newFactory(GitAsyncTaskFactory.class, GitAsyncTask.class));
bind(ContextScopedViewInflatorFactory.class).toProvider(newFactory(ContextScopedViewInflatorFactory.class,
ContextScopedViewInflator.class));
bind(SyncCampaignFactory.class).toProvider(newFactory(SyncCampaignFactory.class, SyncCampaign.class));
bind(TransportConfigCallback.class).to(AgitTransportConfig.class);
bind(CredentialsProvider.class).to(GUICredentialsProvider.class);
bind(SshSessionFactory.class).to(AndroidSshSessionFactory.class);
bind(PromptUIRegistry.class);
bind(HostKeyRepository.class).to(CuriousHostKeyRepository.class);
bind(PromptUI.class).annotatedWith(named("status-bar")).to(StatusBarPromptUI.class);
bind(RepoDomainType.class).annotatedWith(named("branch")).to(RDTBranch.class);
bind(RepoDomainType.class).annotatedWith(named("remote")).to(RDTRemote.class);
bind(RepoDomainType.class).annotatedWith(named("tag")).to(RDTTag.class);
bind(CommitViewHolderFactory.class).toProvider(newFactory(CommitViewHolderFactory.class,
CommitViewHolder.class));
bind(BranchViewHolderFactory.class).toProvider(newFactory(BranchViewHolderFactory.class,
BranchViewHolder.class));
}
示例5: AndroidSshSessionFactory
import com.jcraft.jsch.HostKeyRepository; //导入依赖的package包/类
@Inject
public AndroidSshSessionFactory(Provider<AndroidAuthAgent> androidAuthAgentProvider, UserInfo userInfo,
HostKeyRepository hostKeyRepository) {
this.androidAuthAgentProvider = androidAuthAgentProvider;
this.userInfo = userInfo;
this.hostKeyRepository = hostKeyRepository;
}
示例6: check
import com.jcraft.jsch.HostKeyRepository; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public int check(String host,
byte[] key) {
return HostKeyRepository.OK;
}
示例7: check
import com.jcraft.jsch.HostKeyRepository; //导入依赖的package包/类
@Override
public int check(final String host, final byte[] bkey) {
return HostKeyRepository.OK;
}
示例8: check
import com.jcraft.jsch.HostKeyRepository; //导入依赖的package包/类
@Override
public int check(String host, byte[] key) {
return HostKeyRepository.OK;
}