Results 1 to 15 of 15
Like Tree1Likes
  • 1 Post By Norm

Thread: applet can not enforce my command :(

  1. #1
    tsar4ever's Avatar
    tsar4ever is offline Member
    Join Date
    Aug 2011
    Posts
    9
    Rep Power
    0

    Default applet can not enforce my command :(

    i have 2 classes: Form class and Library class.

    in Form class:
    Java Code:
     JOptionPane.showMessageDialog(null, "go to 1");
                //Get list certificate
    
                libStore = new VNPT_CA_Library();
                int iCheck = 0;
                iCheck = libStore.VNPT_CA_Initialize();
                if (iCheck != 0) {
                    quitApplet();
                }
                JOptionPane.showMessageDialog(null, "go to 2");
    in Library class:
    Java Code:
      public int VNPT_CA_Initialize() {
            Method[] methods = PKCS11.class.getMethods();
            JOptionPane.showMessageDialog(null, "go to 1.1");
            Method p11Getinstance = null;
    
            for (int i = 0; i < methods.length; i++) {
                if (methods[i].getName().equals("getInstance")) {
                    p11Getinstance = methods[i];
                }
            }
    when i embed jar file in html, applet can not show message "go to 1.1", so have a problem with command line: " Method[] methods = PKCS11.class.getMethods();" ?

    Sorry about my Eng

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Sorry, but I don't see enough information here that would allow us to guess at an answer to your question. Please consider providing more information. Please see my second link in my signature below on how to ask smart questions.

  3. #3
    tsar4ever's Avatar
    tsar4ever is offline Member
    Join Date
    Aug 2011
    Posts
    9
    Rep Power
    0

    Default

    Sorry,

    i'm building a applet project about digital certificate. It include two class : form and library.here, i only want to show methods that problem occurs.

    in Form class:
    Java Code:
     private VNPT_CA_Library libStore;
     public int ListCert_Initialize() {
            try {
                frame_Sign = new JFrame("VNPT CA - Chương tržnh ứng dụng PKI");
                frame_Sign.setVisible(true);
                frame_Sign.setLayout(new GridLayout(4, 1));
                frame_Sign.setSize(800, 370);
                frame_Sign.setResizable(false);
                w = frame_Sign.getWidth();
                h = frame_Sign.getHeight();
                //
                pTop = new JPanel();
                pBot = new JPanel();
                p1 = new JPanel();
                p2 = new JPanel();
                p3 = new JPanel();
                frame_Sign.add(pTop);
                frame_Sign.add(p1);
                frame_Sign.add(p2);
                frame_Sign.add(pBot);
                pTop.setBackground(Color.white);
                p1.setBackground(Color.white);
                p2.setBackground(Color.white);
                p3.setBackground(Color.white);
                pBot.setBackground(Color.white);
                JOptionPane.showMessageDialog(null, "go to 1");
                //Get list certificate
    
                libStore = new VNPT_CA_Library();
                int iCheck = 0;
                iCheck = libStore.VNPT_CA_Initialize();
                if (iCheck != 0) {
                    quitApplet();
                }
                JOptionPane.showMessageDialog(null, "go to 2");
                Vector<X509Certificate> Certificates = new Vector<X509Certificate>();
                iCheck = libStore.VNPT_CA_ListCertificate(Certificates);
                if (iCheck != 0) {
                    quitApplet();
                }
                idChoise = 0;
    
    //             Top Image
                lbTop = new JLabel();
                lbTop.setIcon(new ImageIcon(getClass().getResource("/img/top.jpg")));
                pTop.add(lbTop);
    
    //            Bot Image
                lbBot = new JLabel();
                lbBot.setIcon(new ImageIcon(getClass().getResource("/img/bot.jpg")));
                pBot.add(lbBot);
                //
                String abc = new String();
                X509Certificate CertBuf;
                int iList = Certificates.size();
                Object[][] data = new Object[Certificates.size()][3];
                for (int i = 0; i < iList; i++) {
                    CertBuf = Certificates.get(i);
                    data[i][0] = (CertBuf.getSubjectDN().getName());
                    data[i][1] = CertBuf.getNotBefore().toString();
                    data[i][2] = CertBuf.getNotAfter().toString();
                    //abc = CertBuf.getSubjectDN().getName();
                }
                table = new JTable(data, headerName);
                table.setVisible(true);
                table.setPreferredScrollableViewportSize(new Dimension(600, 60));
                p1.add(table);
                scroll = new JScrollPane(table);
                table.setFillsViewportHeight(true);
                p1.add(scroll);
                // button
                btnSign = new JButton("Kż");
                btnSign.setLocation(w / 6, h - 50);
                p2.add(btnSign);
                btnSign.addActionListener(this);
    
                // button
                btnCancel = new JButton("Xem");
                btnCancel.setLocation(w / 6, h - 50);
                p2.add(btnCancel);
                btnCancel.addActionListener(this);
    
                // button
                btnView = new JButton("ThoŠt");
                btnView.setLocation(w / 6, h - 50);
                p2.add(btnView);
                btnView.addActionListener(this);
                return 0;
            } catch (Exception e) {
                return 1;
            }
        }
    and in Library class:

    Java Code:
      public int VNPT_CA_Initialize() {
            Method[] methods = PKCS11.class.getMethods();
            JOptionPane.showMessageDialog(null, "go to 1.1");
            Method p11Getinstance = null;
    
            for (int i = 0; i < methods.length; i++) {
                if (methods[i].getName().equals("getInstance")) {
                    p11Getinstance = methods[i];
                }
            }
    
            try {
                String version = System.getProperty("java.version");
                if (version.indexOf("1.6") > -1 || version.indexOf("1.7") > -1) {
                    // JRE 1.6 , JRE 1.7
                    p11 = (PKCS11) p11Getinstance.invoke(null, new Object[]{_pk11LibPath,
                                "C_GetFunctionList", null, false});
                } else if (version.indexOf("1.5") > -1) {
                    // JRE 1.5
                    p11 = (PKCS11) p11Getinstance.invoke(null,
                            new Object[]{_pk11LibPath, null, false});
                } else {
                    return 10;
                }
                return 0;
            } catch (Exception e) {
                return 10;
            }
        }
    when i enforce project in IDE, no problem, form class can display anything that i build, but when i embed jar file in html, applet can not display table, button,...so only show panels. i put some command to show place where applet can go to (JOptionPane.showMessageDialog commands), and result, applet can show "go to 1" but cannot show "go to 1.1" and "go to 2"
    So there is problem with command line : "Method[] methods = PKCS11.class.getMethods()" in library class. i really don't understands.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,559
    Rep Power
    25

    Default

    when i embed jar file in html, applet can not display table, button,
    Are there any error messages in the browser's java console?

    You could use printlns to print out messages on the java console instead of using JOptionPane.showMessageDialog

  5. #5
    tsar4ever's Avatar
    tsar4ever is offline Member
    Join Date
    Aug 2011
    Posts
    9
    Rep Power
    0

    Default

    when i start my applet in cmd with appletviewer,throw "java.lang.RuntimePermission accessClassInPackage.sun.security.pkcs11.wrapper"



    i was edit java.policy file in (java_home)/jre6/lib/security/ by adding permission:

    grant {
    .....
    .....
    permission java.util.PropertyPermission "java.home", "read";
    permission java.security.SecurityPermission "authProvider.SunPKCS11-FeitianPKCS";
    permission java.lang.RuntimePermission "createClassLoader";
    permission java.lang.RuntimePermission "getClassLoader";
    }

    Java Code:
    p11Getinstance = PKCS11.class.getMethod("getInstance", String.class,
                                    String.class, CK_C_INITIALIZE_ARGS.class, Boolean.TYPE);
    this code is place exception appear.

    help me,pls!

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,559
    Rep Power
    25

    Default

    Does Your console image cut off some of the text?
    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.

    I use the policytool to edit my .java.policy file. That file is located in:
    C:\Documents and Settings\Owner\.java.policy

    The above file is pointed to by the second entry in the .java.security file:

    policy.url.1=file:${java.home}/lib/security/java.policy
    policy.url.2=file:${user.home}/.java.policy

  7. #7
    tsar4ever's Avatar
    tsar4ever is offline Member
    Join Date
    Aug 2011
    Posts
    9
    Rep Power
    0

    Default

    Java Code:
    Microsoft Windows [Version 6.1.7600]
    Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
    
    C:\Users\HoangPTD>cd C:\Program Files\Java\jdk1.6.0_20\bin
    
    C:\Program Files\Java\jdk1.6.0_20\bin>appletviewer.exe test1.html
    java.security.AccessControlException: access denied (java.lang.RuntimePermission
     accessClassInPackage.sun.security.pkcs11.wrapper)
            at java.security.AccessControlContext.checkPermission(AccessControlConte
    xt.java:323)
            at java.security.AccessController.checkPermission(AccessController.java:
    546)
            at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
            at java.lang.SecurityManager.checkPackageAccess(SecurityManager.java:151
    2)
            at sun.applet.AppletSecurity.checkPackageAccess(AppletSecurity.java:266)
    
            at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:141)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
            at VNPT_CA.SmartCardSigner.VNPT_CA_Lib$1.run(VNPT_CA_Lib.java:74)
            at java.security.AccessController.doPrivileged(Native Method)
            at VNPT_CA.SmartCardSigner.VNPT_CA_Lib.VNPT_CA_Initialize(VNPT_CA_Lib.ja
    va:70)
            at VNPT_CA.Applet.VNPT_CA_Certificate.ListCert_Initialize(VNPT_CA_Certif
    icate.java:81)
            at VNPT_CA.Applet.SmartCardSignerApplet.signSelectedFile(SmartCardSigner
    Applet.java:64)
            at VNPT_CA.Applet.SmartCardSignerApplet.access$000(SmartCardSignerApplet
    .java:20)
            at VNPT_CA.Applet.SmartCardSignerApplet$1.actionPerformed(SmartCardSigne
    rApplet.java:40)
            at java.awt.Button.processActionEvent(Button.java:392)
            at java.awt.Button.processEvent(Button.java:360)
            at java.awt.Component.dispatchEventImpl(Component.java:4630)
            at java.awt.Component.dispatchEvent(Component.java:4460)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
            at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre
    ad.java:269)
            at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.
    java:184)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
    ad.java:174)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
    
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
    
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
    java.lang.NullPointerException
            at VNPT_CA.SmartCardSigner.VNPT_CA_Lib.VNPT_CA_Initialize(VNPT_CA_Lib.ja
    va:92)
            at VNPT_CA.Applet.VNPT_CA_Certificate.ListCert_Initialize(VNPT_CA_Certif
    icate.java:81)
            at VNPT_CA.Applet.SmartCardSignerApplet.signSelectedFile(SmartCardSigner
    Applet.java:64)
            at VNPT_CA.Applet.SmartCardSignerApplet.access$000(SmartCardSignerApplet
    .java:20)
            at VNPT_CA.Applet.SmartCardSignerApplet$1.actionPerformed(SmartCardSigne
    rApplet.java:40)
            at java.awt.Button.processActionEvent(Button.java:392)
            at java.awt.Button.processEvent(Button.java:360)
            at java.awt.Component.dispatchEventImpl(Component.java:4630)
            at java.awt.Component.dispatchEvent(Component.java:4460)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
            at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre
    ad.java:269)
            at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.
    java:184)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
    ad.java:174)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
    
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
    
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
    this is full of command prompt window.

    i don't really understand your comment. what's name of your tool? i try to find in my computer but i don't see it. could you give me some clear suggestions? thks!

  8. #8
    tsar4ever's Avatar
    tsar4ever is offline Member
    Join Date
    Aug 2011
    Posts
    9
    Rep Power
    0

    Default

    my program is a application for client, so edit java lib is a end solution. now, i want to edit my code to avoid above exception. i edit my error code as follows:

    Java Code:
      AccessController.doPrivileged(new PrivilegedAction() {
    
                    public Object run() {
                        try {
                            p11Getinstance = PKCS11.class.getMethod("getInstance", String.class,
                                    String.class, CK_C_INITIALIZE_ARGS.class, Boolean.TYPE);
                        } catch (Exception ex) {
                            ex.printStackTrace();
                        }
                        return null;
                    }
                });
    but my applet does not still run successfully! :(

  9. #9
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,559
    Rep Power
    25

    Default

    what's name of your tool?
    The policytool.exe program comes with the jre and is in the jre's bin folder.

  10. #10
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,559
    Rep Power
    25

    Default

    accessClassInPackage.sun.security.pkcs11.wrapper
    Have you tried this policy file statement:
    java.lang.RuntimePermission "accessClassInPackage.sun.security.pkcs11.wrap per"
    tsar4ever likes this.

  11. #11
    tsar4ever's Avatar
    tsar4ever is offline Member
    Join Date
    Aug 2011
    Posts
    9
    Rep Power
    0

    Default

    Thanks!
    Base on your suggestion, i edit file java.policy with statament: java.lang.RuntimePermission "accessClassInPackage.sun.security.pkcs11.wrapper" , and now i want to edit my source code, not library.

  12. #12
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,559
    Rep Power
    25

    Default

    now i want to edit my source code,
    Is there a problem? Can you explain?

  13. #13
    tsar4ever's Avatar
    tsar4ever is offline Member
    Join Date
    Aug 2011
    Posts
    9
    Rep Power
    0

    Default

    i use jarsigned in jdk/bin forder to sign my jar file, and i clear statement java.lang.RuntimePermission "accessClassInPackage.sun.security.pkcs11.wrap per" in java lib, the exception still appear.

    i try to edit my code following:
    Java Code:
      AccessController.doPrivileged(new PrivilegedAction() {
    
                    @Override
                    public Object run() {
                        try {
                            p11Getinstance = PKCS11.class.getMethod("getInstance", String.class,
                                    String.class, CK_C_INITIALIZE_ARGS.class, Boolean.TYPE);
                        } catch (Exception ex) {
                            ex.printStackTrace();
                        }
                        return null;
                    }
                });
    but not success!

  14. #14
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,559
    Rep Power
    25

    Default

    Does your code work when you execute it from an application?

  15. #15
    tsar4ever's Avatar
    tsar4ever is offline Member
    Join Date
    Aug 2011
    Posts
    9
    Rep Power
    0

Similar Threads

  1. Letting my program command the command prompt
    By Smokey. in forum Threads and Synchronization
    Replies: 4
    Last Post: 03-29-2011, 11:34 PM
  2. Replies: 4
    Last Post: 07-22-2010, 11:22 AM
  3. Running applet from command prompt
    By niteshwar.bhardwaj in forum Java 2D
    Replies: 1
    Last Post: 03-12-2009, 08:10 AM
  4. Unable to execute command line command in java
    By LordSM in forum New To Java
    Replies: 1
    Last Post: 08-08-2007, 12:23 AM
  5. Replies: 4
    Last Post: 06-08-2007, 06:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •