~ubuntu-branches/ubuntu/saucy/jenkins/saucy-proposed

« back to all changes in this revision

Viewing changes to cli/src/main/java/hudson/cli/CLI.java

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-13 12:35:19 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20130813123519-tizgfxcr70trl7r0
Tags: 1.509.2+dfsg-1
* New upstream release (Closes: #706725):
  - d/control: Update versioned BD's:
    * jenkins-executable-war >= 1.28.
    * jenkins-instance-identity >= 1.3.
    * libjenkins-remoting-java >= 2.23.
    * libjenkins-winstone-java >= 0.9.10-jenkins-44.
    * libstapler-java >= 1.207.
    * libjenkins-json-java >= 2.4-jenkins-1.
    * libstapler-adjunct-timeline-java >= 1.4.
    * libstapler-adjunct-codemirror-java >= 1.2.
    * libmaven-hpi-plugin-java >= 1.93.
    * libjenkins-xstream-java >= 1.4.4-jenkins-3.
  - d/maven.rules: Map to older version of animal-sniffer-maven-plugin.
  - Add patch for compatibility with guava >= 0.14.
  - Add patch to exclude asm4 dependency via jnr-posix.
  - Fixes the following security vulnerabilities:
    CVE-2013-2034, CVE-2013-2033, CVE-2013-2034, CVE-2013-1808
* d/patches/*: Switch to using git patch-queue for managing patches.
* De-duplicate jars between libjenkins-java and jenkins-external-job-monitor
  (Closes: #701163):
  - d/control: Add dependency between jenkins-external-job-monitor ->
    libjenkins-java.
  - d/rules: 
    Drop installation of jenkins-core in jenkins-external-job-monitor.
  - d/jenkins-external-job-monitor.{links,install}: Link to jenkins-core
    in /usr/share/java instead of included version.
* Wait longer for jenkins to stop during restarts (Closes: #704848):
  - d/jenkins.init: Re-sync init script from upstream codebase.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
import hudson.remoting.RemoteOutputStream;
33
33
import hudson.remoting.SocketInputStream;
34
34
import hudson.remoting.SocketOutputStream;
 
35
import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement;
35
36
 
36
 
import javax.crypto.KeyAgreement;
37
37
import javax.crypto.SecretKey;
38
38
import javax.crypto.spec.SecretKeySpec;
 
39
import javax.net.ssl.HostnameVerifier;
 
40
import javax.net.ssl.HttpsURLConnection;
 
41
import javax.net.ssl.SSLContext;
 
42
import javax.net.ssl.SSLSession;
 
43
import javax.net.ssl.TrustManager;
39
44
import java.io.BufferedInputStream;
40
45
import java.io.BufferedOutputStream;
41
46
import java.io.BufferedReader;
60
65
import java.security.KeyFactory;
61
66
import java.security.KeyPair;
62
67
import java.security.PublicKey;
 
68
import java.security.SecureRandom;
63
69
import java.security.Signature;
64
70
import java.security.spec.DSAPrivateKeySpec;
65
71
import java.security.spec.DSAPublicKeySpec;
66
 
import java.security.spec.X509EncodedKeySpec;
67
72
import java.util.ArrayList;
68
73
import java.util.Arrays;
69
74
import java.util.Collections;
124
129
        ownsPool = exec==null;
125
130
        pool = exec!=null ? exec : Executors.newCachedThreadPool();
126
131
 
127
 
        Channel channel = null;
128
 
        CliPort clip = getCliTcpPort(url);
129
 
        if(clip!=null) {
130
 
            // connect via CLI port
 
132
        Channel _channel;
 
133
        try {
 
134
            _channel = connectViaCliPort(jenkins, getCliTcpPort(url));
 
135
        } catch (IOException e) {
 
136
            LOGGER.log(Level.FINE,"Failed to connect via CLI port. Falling back to HTTP",e);
131
137
            try {
132
 
                channel = connectViaCliPort(jenkins, clip);
133
 
            } catch (IOException e) {
134
 
                LOGGER.log(Level.FINE,"Failed to connect via CLI port. Falling back to HTTP",e);
 
138
                _channel = connectViaHttp(url);
 
139
            } catch (IOException e2) {
 
140
                try { // Java 7: e.addSuppressed(e2);
 
141
                    Throwable.class.getMethod("addSuppressed", Throwable.class).invoke(e, e2);
 
142
                } catch (NoSuchMethodException _ignore) {
 
143
                    // Java 6
 
144
                } catch (Exception _huh) {
 
145
                    LOGGER.log(Level.SEVERE, null, _huh);
 
146
                }
 
147
                throw e;
135
148
            }
136
149
        }
137
 
        if (channel==null) {
138
 
            // connect via HTTP
139
 
            channel = connectViaHttp(url);
140
 
        }
141
 
        this.channel = channel;
 
150
        this.channel = _channel;
142
151
 
143
152
        // execute the command
144
 
        entryPoint = (CliEntryPoint)channel.waitForRemoteProperty(CliEntryPoint.class.getName());
 
153
        entryPoint = (CliEntryPoint)_channel.waitForRemoteProperty(CliEntryPoint.class.getName());
145
154
 
146
155
        if(entryPoint.protocolVersion()!=CliEntryPoint.VERSION)
147
156
            throw new IOException(Messages.CLI_VersionMismatch());
274
283
        String identity = head.getHeaderField("X-Instance-Identity");
275
284
 
276
285
        flushURLConnection(head);
277
 
        if (p1==null && p2==null)     return null;
 
286
        if (p1==null && p2==null) {
 
287
            throw new IOException("No X-Jenkins-CLI2-Port among " + head.getHeaderFields().keySet());
 
288
        }
278
289
 
279
290
        if (p2!=null)   return new CliPort(new InetSocketAddress(h,Integer.parseInt(p2)),identity,2);
280
291
        else            return new CliPort(new InetSocketAddress(h,Integer.parseInt(p1)),identity,1);
395
406
                args = args.subList(2,args.size());
396
407
                continue;
397
408
            }
 
409
            if (head.equals("-noCertificateCheck")) {
 
410
                System.out.println("Skipping HTTPS certificate checks altogether. Note that this is not secure at all.");
 
411
                SSLContext context = SSLContext.getInstance("TLS");
 
412
                context.init(null, new TrustManager[]{new NoCheckTrustManager()}, new SecureRandom());
 
413
                HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
 
414
                // bypass host name check, too.
 
415
                HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
 
416
                    public boolean verify(String s, SSLSession sslSession) {
 
417
                        return true;
 
418
                    }
 
419
                });
 
420
                args = args.subList(1,args.size());
 
421
                continue;
 
422
            }
398
423
            if(head.equals("-i") && args.size()>=2) {
399
424
                File f = new File(args.get(1));
400
425
                if (!f.exists()) {
435
460
        if (candidateKeys.isEmpty())
436
461
            addDefaultPrivateKeyLocations(candidateKeys);
437
462
 
438
 
        CLI cli = new CLIConnectionFactory().url(url).httpsProxyTunnel(httpProxy).connect();
 
463
        CLIConnectionFactory factory = new CLIConnectionFactory().url(url).httpsProxyTunnel(httpProxy);
 
464
        String userInfo = new URL(url).getUserInfo();
 
465
        if (userInfo != null) {
 
466
            factory = factory.basicAuth(userInfo);
 
467
        }
 
468
 
 
469
        CLI cli = factory.connect();
439
470
        try {
440
471
            if (!candidateKeys.isEmpty()) {
441
472
                try {
546
577
    }
547
578
    
548
579
    @SuppressWarnings("Since15")
 
580
    @IgnoreJRERequirement
549
581
    private static String askForPasswd(String filePath){
550
582
        try {
551
583
            Console cons = System.console();