jfreesane icon indicating copy to clipboard operation
jfreesane copied to clipboard

About authentication

Open jurivrljicak opened this issue 4 years ago • 13 comments

Hello,

I don't understand why sometimes I am asked to authenticate and sometimes I am not. Can I disable this functionality?

If I choose to enable it, I am not very clear how to use it either.

I put this file in place.

~/.sane/pass This file contains lines of the form user:password:resource

...where the password is the default pass for a particular device? (I can't find that on the manual)

thanks a lot

java.io.IOException: Authorization failed - the password provider is unable to provide a password for the resource [
     at au.com.southsky.jfreesane.SaneSession.authorize(SaneSession.java:351)
     at au.com.southsky.jfreesane.SaneSession.openDevice(SaneSession.java:195)
     at au.com.southsky.jfreesane.SaneDevice.open(SaneDevice.java:77)
     at com.xxx.service.image.manager.sane.jsane.JSaneDeviceImpl$2.doWithRetry(JSaneDeviceImpl.java:248)
     at com.xxx.service.image.manager.sane.jsane.JSaneDeviceImpl$2.doWithRetry(JSaneDeviceImpl.java:1)
     at org.springframework.retry.support.RetryTemplate.doExecute(RetryTemplate.java:329)
     at org.springframework.retry.support.RetryTemplate.execute(RetryTemplate.java:209)
     at com.xxx.service.image.manager.sane.jsane.JSaneDeviceImpl.openDevice(JSaneDeviceImpl.java:243)

jurivrljicak avatar Jan 28 '21 18:01 jurivrljicak

Are any of your resources password-protected? What does /etc/sane.d/saned.users contain?

The format of the password file is <user>:<password>:<resource>, see man saned(2):

       /etc/sane.d/saned.users
              If this file contains lines of the form

              user:password:backend

              access to the listed backends is restricted. A backend may be listed multiple times for different user/password combinations. The server uses MD5 hashing if supported by the
              client.

sjamesr avatar Jan 28 '21 20:01 sjamesr

I am sorry I don't follow from before. How do I set up a password? thanks

jurivrljicak avatar Jan 29 '21 17:01 jurivrljicak

You have to look at the SANE server configuration to see if any of the resources (i.e. scanners) are password protected. Does your server have a /etc/sane.d/saned.users file?

sjamesr avatar Jan 29 '21 18:01 sjamesr

no it does'nt.

But why don't I get a consistent behavior in here?


SaneDeviceHandle openDevice(SaneDevice device) throws IOException, SaneException {

    [...code..]

    SaneWord handle = inputStream.readWord();
    String resource = inputStream.readString();

    if (!resource.isEmpty()) {
      authorize(resource);
      status = inputStream.readWord();
      handle = inputStream.readWord();
      resource = inputStream.readString();
      if (status.integerValue() != 0) {
        throw new SaneException(SaneStatus.fromWireValue(status.integerValue()));
      }
    }

    return new SaneDeviceHandle(status, handle, resource);
  }

jurivrljicak avatar Jan 29 '21 18:01 jurivrljicak

Can you send me the code that you're using to call into JFreeSane? Are you saying you have no passwords configured on any of your scanners, yet JFreeSane is still trying to authenticate? If so, perhaps you could capture a packet dump of an interaction between JFreeSane and SANE, e.g.

tcpdump port 6566 -w /tmp/out.pcap
<run jfreesane>

and send me the resulting out.pcap.

sjamesr avatar Feb 07 '21 15:02 sjamesr

Ok I'll try that and I'll be back, thank you.

Are you saying you have no passwords configured on any of your scanners, yet JFreeSane is still trying to authenticate?

Yes.

In the meantime this is what I have:

INFO: KODAK/i900/sheetfed scanner Jan 30, 2021 9:40:57 AM com.xxx.service.image.manager.sane.jsane.JSaneDeviceImpl$3 onError SEVERE: Error trying operation: Connect to Jsane device, occ=1, excep= au.com.southsky.jfreesane.SaneException:STATUS_INVAL Jan 30, 2021 9:41:12 AM com.xxx.service.image.manager.sane.jsane.JSaneDeviceImpl$3 onError SEVERE: Error trying operation: Connect to Jsane device, occ=2, excep= java.io.IOException:Authorization failed - the password provider is unable to provide a password for the resource [

The resource is '[' and I don't know what that means. In the case where it works the resource is '' (empty). I guess that is what I want.

jurivrljicak avatar Feb 07 '21 15:02 jurivrljicak

Yeah it definitely looks like something is going wrong in the stream, most likely a bug in jfreesane somewhere. Hopefully I'll be able to track it down with a pcap dump.

Thanks for reporting it.

On Sun, Feb 7, 2021 at 7:23 AM jurivrljicak [email protected] wrote:

Ok I'll try that and I'll be back, thank you.

In the meantime this is what I have:

INFO: KODAK/i900/sheetfed scanner Jan 30, 2021 9:40:57 AM com.xxx.service.image.manager.sane.jsane.JSaneDeviceImpl$3 onError SEVERE: Error trying operation: Connect to Jsane device, occ=1, excep= au.com.southsky.jfreesane.SaneException:STATUS_INVAL Jan 30, 2021 9:41:12 AM com.aws.service.image.manager.sane.jsane.JSaneDeviceImpl$3 onError SEVERE: Error trying operation: Connect to Jsane device, occ=2, excep= java.io.IOException:Authorization failed - the password provider is unable to provide a password for the resource [

The resource is '[' and I don't know what that means. In the case where it works the resource is '' (empty). I guess that is what I want.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/sjamesr/jfreesane/issues/104#issuecomment-774692281, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABDNGAZKIMZPHGI462R34B3S52V6DANCNFSM4WXQ6QCA .

sjamesr avatar Feb 07 '21 15:02 sjamesr

Ok great I'll try to get to into that condition. It's kind of random or somehow related to when things get idle for some time. Thanks!

jurivrljicak avatar Feb 07 '21 15:02 jurivrljicak

I made a capture with Wireshark for my virtual machine interface to capture something. With the command you mentioned I got nothing for that port (I am using that default port).

Got the error and reran the code

Here it is what I got , let me know if its of any use.

authenticationJfreeSane.pcapng.zip

jurivrljicak avatar Feb 10 '21 18:02 jurivrljicak

Here is another, thanks

out.pcap.zip

jurivrljicak avatar Feb 11 '21 16:02 jurivrljicak

I haven't found a solution yet but I have a hint.

Before the authentication error I get a INVAL status. Looks like the connection gets into that state for some reason (not sure what reason). If I close and open the cover of my kodak things go back to normal. I have to emulate that manual procedure in the code as a workaround....I guess.

jurivrljicak avatar Feb 26 '21 21:02 jurivrljicak

I didn't find any SANE traffic in either of the packet dumps you sent me. Can you share the code that uses jfreesane?

Do you call listDevices() and get back an empty list at any point? If so, that was fixed by https://github.com/sjamesr/jfreesane/pull/101 and you might want to try jfreesane built from HEAD.

sjamesr avatar Feb 26 '21 21:02 sjamesr

Well, that fix made no difference.

My workaround when I get into that state (INVAL) is to restart the saned deamon from the app and things get back to work.

Ok, thx for your time. Cheers

jurivrljicak avatar Mar 03 '21 19:03 jurivrljicak